Skip to content

Commit 767ccd3

Browse files
Merge pull request nestjs#1103 from jbpionnier/refactor/enable_strict_mode
refactor(nestjs) enable strict mode
2 parents 0368d52 + d37ec23 commit 767ccd3

10 files changed

Lines changed: 25 additions & 14 deletions

File tree

packages/common/pipes/validation.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let classTransformer: any = {};
1717
@Injectable()
1818
export class ValidationPipe implements PipeTransform<any> {
1919
protected isTransformEnabled: boolean;
20-
protected isDetailedOutputDisabled: boolean;
20+
protected isDetailedOutputDisabled?: boolean;
2121
protected validatorOptions: ValidatorOptions;
2222

2323
constructor(@Optional() options?: ValidationPipeOptions) {

packages/common/services/logger.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export interface LoggerService {
1313

1414
@Injectable()
1515
export class Logger implements LoggerService {
16-
private static prevTimestamp = null;
16+
private static prevTimestamp?: number;
1717
private static contextEnvironment = NestEnvironment.RUN;
18-
private static logger: typeof Logger | LoggerService = Logger;
18+
private static logger?: typeof Logger | LoggerService = Logger;
1919
private static readonly yellow = clc.xterm(3);
2020

2121
constructor(
@@ -52,7 +52,7 @@ export class Logger implements LoggerService {
5252
}
5353

5454
static overrideLogger(logger: LoggerService | boolean) {
55-
this.logger = logger ? (logger as LoggerService) : null;
55+
this.logger = logger ? (logger as LoggerService) : undefined;
5656
}
5757

5858
static setMode(mode: NestEnvironment) {

packages/common/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"sourceMap": false,
1313
"allowJs": false,
1414
"rootDir": "./",
15+
"strict": true,
16+
"strictNullChecks": false,
1517
"outDir": "../../node_modules/@nestjs/common"
1618
},
1719
"include": [

packages/core/injector/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class Module {
241241
}
242242

243243
public addCustomClass(component: CustomClass, collection: Map<string, any>) {
244-
const { provide, name, useClass } = component;
244+
const { name, useClass } = component;
245245
collection.set(name, {
246246
name,
247247
metatype: useClass,
@@ -251,7 +251,7 @@ export class Module {
251251
}
252252

253253
public addCustomValue(component: CustomValue, collection: Map<string, any>) {
254-
const { provide, name, useValue: value } = component;
254+
const { name, useValue: value } = component;
255255
collection.set(name, {
256256
name,
257257
metatype: null,
@@ -266,7 +266,7 @@ export class Module {
266266
component: CustomFactory,
267267
collection: Map<string, any>,
268268
) {
269-
const { provide, name, useFactory: factory, inject } = component;
269+
const { name, useFactory: factory, inject } = component;
270270
collection.set(name, {
271271
name,
272272
metatype: factory as any,

packages/core/middleware/middleware-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export class MiddlewareModule {
107107
) {
108108
const { forRoutes } = config;
109109
await Promise.all(
110-
forRoutes.map(async (routeInfo: RouteInfo) => {
110+
forRoutes.map(async (routeInfo: Type<any> | string | RouteInfo) => {
111111
await this.registerRouteMiddleware(
112112
middlewareContainer,
113-
routeInfo,
113+
routeInfo as RouteInfo,
114114
config,
115115
module,
116116
applicationRef,

packages/core/nest-application.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as http from 'http';
2727
import * as https from 'https';
2828
import iterate from 'iterare';
2929
import * as optional from 'optional';
30+
import { RequestHandler } from '../common/interfaces';
3031
import { ExpressAdapter } from './adapters/express-adapter';
3132
import { FastifyAdapter } from './adapters/fastify-adapter';
3233
import { ApplicationConfig } from './application-config';
@@ -286,7 +287,7 @@ export class NestApplication extends NestApplicationContext
286287
}
287288

288289
public enableCors(options?: CorsOptions): this {
289-
this.httpAdapter.use(cors(options));
290+
this.httpAdapter.use(cors(options) as RequestHandler);
290291
return this;
291292
}
292293

packages/core/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"sourceMap": false,
1313
"allowJs": false,
1414
"rootDir": "./",
15-
"baseUrl": "./../../",
15+
"baseUrl": "../../",
16+
"strict": true,
17+
"strictNullChecks": false,
18+
"noImplicitThis": false,
1619
"outDir": "../../node_modules/@nestjs/core"
1720
},
1821
"include": [

packages/microservices/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"target": "es2017",
1212
"sourceMap": false,
1313
"allowJs": false,
14-
"baseUrl": "./../../",
14+
"baseUrl": "../../",
15+
"strict": true,
16+
"strictNullChecks": false,
1517
"outDir": "../../node_modules/@nestjs/microservices"
1618
},
1719
"include": [

packages/testing/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"target": "es2017",
1212
"sourceMap": false,
1313
"allowJs": false,
14-
"baseUrl": "./../../",
14+
"baseUrl": "../../",
15+
"strict": true,
1516
"outDir": "../../node_modules/@nestjs/testing"
1617
},
1718
"include": [

packages/websockets/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"target": "es2017",
1212
"sourceMap": false,
1313
"allowJs": false,
14-
"baseUrl": "./../../",
14+
"baseUrl": "../../",
15+
"strict": true,
16+
"strictNullChecks": false,
1517
"outDir": "../../node_modules/@nestjs/websockets"
1618
},
1719
"include": [

0 commit comments

Comments
 (0)