build: use strict null checks part 5

This commit is contained in:
Kamil Myśliwiec
2024-11-26 14:39:51 +01:00
parent 5b220df118
commit 7d3e5c1a38
75 changed files with 98 additions and 75 deletions

View File

@@ -4,6 +4,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import * as sinon from 'sinon'; import * as sinon from 'sinon';
import { BarService } from '../src/bar.service'; import { BarService } from '../src/bar.service';
import { FooService } from '../src/foo.service'; import { FooService } from '../src/foo.service';
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
const { expect } = chai; const { expect } = chai;

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -17,17 +17,17 @@ export class WebhooksExplorer {
const { name } = this.discoveryService.getMetadataByDecorator( const { name } = this.discoveryService.getMetadataByDecorator(
Webhook, Webhook,
wrapper, wrapper,
); )!;
return { return {
name, name,
handlers: this.metadataScanner handlers: this.metadataScanner
.getAllMethodNames(wrapper.metatype.prototype) .getAllMethodNames(wrapper.metatype!.prototype)
.map(methodName => { .map(methodName => {
const { event } = this.discoveryService.getMetadataByDecorator( const { event } = this.discoveryService.getMetadataByDecorator(
WebhookHandler, WebhookHandler,
wrapper, wrapper,
methodName, methodName,
); )!;
return { return {
methodName, methodName,
event, event,

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -20,6 +20,6 @@ export class CatsRequestScopedService {
} }
findOneById(id: number): Cat { findOneById(id: number): Cat {
return this.cats.find(cat => cat.id === id); return this.cats.find(cat => cat.id === id)!;
} }
} }

View File

@@ -20,6 +20,6 @@ export class CatsService {
} }
findOneById(id: number): Cat { findOneById(id: number): Cat {
return this.cats.find(cat => cat.id === id); return this.cats.find(cat => cat.id === id)!;
} }
} }

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -6,7 +6,7 @@ export class CircularModule {
const a = { const a = {
module: CircularModule, module: CircularModule,
providers: [InputService], providers: [InputService],
b: null, b: null as any,
}; };
a.b = a; a.b = a;
return a; return a;

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -100,7 +100,7 @@ describe.skip('Kafka concurrent', function () {
} }
} }
if (topicMetadata && topicMetadata.topics.length > 0) { if (topicMetadata! && topicMetadata.topics.length > 0) {
// we have topics, how many partitions do they have? // we have topics, how many partitions do they have?
for (const topic of topicMetadata.topics) { for (const topic of topicMetadata.topics) {
if (topic.partitions.length < numbersOfServers) { if (topic.partitions.length < numbersOfServers) {

View File

@@ -123,7 +123,7 @@ describe.skip('Kafka transport', function () {
}); });
it(`/POST (sync command create user) Concurrency Test`, async () => { it(`/POST (sync command create user) Concurrency Test`, async () => {
const promises = []; const promises = [] as Array<Promise<any>>;
for (let concurrencyKey = 0; concurrencyKey < 100; concurrencyKey++) { for (let concurrencyKey = 0; concurrencyKey < 100; concurrencyKey++) {
const innerUserDto = JSON.parse(JSON.stringify(userDto)); const innerUserDto = JSON.parse(JSON.stringify(userDto));
innerUserDto.name += `+${concurrencyKey}`; innerUserDto.name += `+${concurrencyKey}`;

View File

@@ -17,7 +17,7 @@ import { SumDto } from './dto/sum.dto';
*/ */
const explicitPartitioner = () => { const explicitPartitioner = () => {
return ({ message }: PartitionerArgs) => { return ({ message }: PartitionerArgs) => {
return parseFloat(message.headers.toPartition.toString()); return parseFloat(message.headers!.toPartition!.toString());
}; };
}; };

View File

@@ -138,7 +138,7 @@ export class MqttController {
} }
@MessagePattern('wildcard-message/#') @MessagePattern('wildcard-message/#')
wildcardMessageHandler(data: number[]): number { wildcardMessageHandler(data: number[]): number | undefined {
if ((data as any).response) { if ((data as any).response) {
return; return;
} }
@@ -186,7 +186,7 @@ export class MqttController {
} }
@MessagePattern('$share/test-group/shared-wildcard-message/#') @MessagePattern('$share/test-group/shared-wildcard-message/#')
sharedWildcardMessageHandler(data: number[]): number { sharedWildcardMessageHandler(data: number[]): number | undefined {
if ((data as any).response) { if ((data as any).response) {
return; return;
} }

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -11,6 +11,7 @@
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"outDir": "./dist", "outDir": "./dist",
"strictNullChecks": true,
"paths": { "paths": {
"@nestjs/common": ["../../../packages/common"], "@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"], "@nestjs/common/*": ["../../../packages/common/*"],

View File

@@ -11,6 +11,7 @@
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"outDir": "./dist", "outDir": "./dist",
"strictNullChecks": true,
"paths": { "paths": {
"@nestjs/common": ["../../../packages/common"], "@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"], "@nestjs/common/*": ["../../../packages/common/*"],

View File

@@ -11,6 +11,7 @@
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"outDir": "./dist", "outDir": "./dist",
"strictNullChecks": true,
"paths": { "paths": {
"@nestjs/common": ["../../../packages/common"], "@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"], "@nestjs/common/*": ["../../../packages/common/*"],

View File

@@ -11,6 +11,7 @@
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"outDir": "./dist", "outDir": "./dist",
"strictNullChecks": true,
"paths": { "paths": {
"@nestjs/common": ["../../../packages/common"], "@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"], "@nestjs/common/*": ["../../../packages/common/*"],

View File

@@ -7,7 +7,7 @@ export class ExpressController {
getRawBody(@Req() req: RawBodyRequest<Request>) { getRawBody(@Req() req: RawBodyRequest<Request>) {
return { return {
parsed: req.body, parsed: req.body,
raw: req.rawBody.toString(), raw: req.rawBody!.toString(),
}; };
} }
} }

View File

@@ -7,7 +7,7 @@ export class FastifyController {
getRawBody(@Req() req: RawBodyRequest<FastifyRequest>) { getRawBody(@Req() req: RawBodyRequest<FastifyRequest>) {
return { return {
parsed: req.body, parsed: req.body,
raw: req.rawBody.toString(), raw: req.rawBody!.toString(),
}; };
} }
} }

View File

@@ -11,6 +11,7 @@
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"outDir": "./dist", "outDir": "./dist",
"strictNullChecks": true,
"paths": { "paths": {
"@nestjs/common": ["../../../packages/common"], "@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"], "@nestjs/common/*": ["../../../packages/common/*"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -9,7 +9,7 @@ export class DurableContextIdStrategy implements ContextIdStrategy {
let tenantSubTreeId: ContextId; let tenantSubTreeId: ContextId;
if (tenants.has(tenantId)) { if (tenants.has(tenantId)) {
tenantSubTreeId = tenants.get(tenantId); tenantSubTreeId = tenants.get(tenantId)!;
} else { } else {
tenantSubTreeId = { id: +tenantId } as ContextId; tenantSubTreeId = { id: +tenantId } as ContextId;
tenants.set(tenantId, tenantSubTreeId); tenants.set(tenantId, tenantSubTreeId);

View File

@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class Guard implements CanActivate { export class Guard implements CanActivate {
static COUNTER = 0; static COUNTER = 0;
static REQUEST_SCOPED_DATA = []; static REQUEST_SCOPED_DATA = [] as number[];
constructor(@Inject('REQUEST_ID') private readonly requestId: number) { constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
Guard.COUNTER++; Guard.COUNTER++;

View File

@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class Interceptor implements NestInterceptor { export class Interceptor implements NestInterceptor {
static COUNTER = 0; static COUNTER = 0;
static REQUEST_SCOPED_DATA = []; static REQUEST_SCOPED_DATA = [] as number[];
constructor(@Inject('REQUEST_ID') private readonly requestId: number) { constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
Interceptor.COUNTER++; Interceptor.COUNTER++;

View File

@@ -9,7 +9,7 @@ import { UsersService } from './users.service';
@Injectable() @Injectable()
export class UserByIdPipe implements PipeTransform<string> { export class UserByIdPipe implements PipeTransform<string> {
static COUNTER = 0; static COUNTER = 0;
static REQUEST_SCOPED_DATA = []; static REQUEST_SCOPED_DATA = [] as number[];
constructor( constructor(
@Inject('REQUEST_ID') private readonly requestId: number, @Inject('REQUEST_ID') private readonly requestId: number,

View File

@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class Guard implements CanActivate { export class Guard implements CanActivate {
static COUNTER = 0; static COUNTER = 0;
static REQUEST_SCOPED_DATA = []; static REQUEST_SCOPED_DATA = [] as number[];
constructor(@Inject('REQUEST_ID') private readonly requestId: number) { constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
Guard.COUNTER++; Guard.COUNTER++;

View File

@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class Interceptor implements NestInterceptor { export class Interceptor implements NestInterceptor {
static COUNTER = 0; static COUNTER = 0;
static REQUEST_SCOPED_DATA = []; static REQUEST_SCOPED_DATA = [] as number[];
constructor(@Inject('REQUEST_ID') private readonly requestId: number) { constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
Interceptor.COUNTER++; Interceptor.COUNTER++;

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -14,7 +14,7 @@ describe('Custom Versioning (fastify)', () => {
.flatMap(v => v.split(',')) .flatMap(v => v.split(','))
.map(header => header.match(/v(\d+\.?\d*)\+json$/)) .map(header => header.match(/v(\d+\.?\d*)\+json$/))
.filter(match => match && match.length) .filter(match => match && match.length)
.map(matchArray => matchArray[1]) .map(matchArray => matchArray![1])
.sort() .sort()
.reverse(); .reverse();

View File

@@ -11,11 +11,11 @@ describe('Custom Versioning', () => {
?.split(',') ?.split(',')
.map(header => header.match(/v(\d+\.?\d*)\+json$/)) .map(header => header.match(/v(\d+\.?\d*)\+json$/))
.filter(match => match && match.length) .filter(match => match && match.length)
.map(matchArray => matchArray[1]) .map(matchArray => matchArray![1])
.sort() .sort()
.reverse(); .reverse();
return versions; return versions!;
}; };
let app: INestApplication; let app: INestApplication;

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -11,7 +11,7 @@ describe('ErrorGateway', () => {
const testingModule = await Test.createTestingModule({ const testingModule = await Test.createTestingModule({
providers: [ErrorGateway], providers: [ErrorGateway],
}).compile(); }).compile();
app = testingModule.createNestApplication(); app = testingModule.createNestApplication();
await app.listen(3000); await app.listen(3000);
}); });

View File

@@ -10,6 +10,7 @@
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"outDir": "./dist", "outDir": "./dist",
"paths": { "paths": {
"@nestjs/common": ["../../packages/common"], "@nestjs/common": ["../../packages/common"],

View File

@@ -139,7 +139,7 @@ export class HttpException extends IntrinsicException {
if (isString(arg0) || Array.isArray(arg0) || isNumber(arg0)) { if (isString(arg0) || Array.isArray(arg0) || isNumber(arg0)) {
return { return {
message: arg0!, message: arg0,
error: arg1 as string, error: arg1 as string,
statusCode: statusCode!, statusCode: statusCode!,
}; };
@@ -153,7 +153,7 @@ export class HttpException extends IntrinsicException {
): string { ): string {
return isString(descriptionOrOptions) return isString(descriptionOrOptions)
? descriptionOrOptions ? descriptionOrOptions
: descriptionOrOptions?.description!; : (descriptionOrOptions?.description as string);
} }
public static getHttpExceptionOptionsFrom( public static getHttpExceptionOptionsFrom(

View File

@@ -269,7 +269,7 @@ export class ConfigurableModuleBuilder<
const moduleOptions = {}; const moduleOptions = {};
const extrasKeys = Object.keys(extras); const extrasKeys = Object.keys(extras);
Object.keys(input!) Object.keys(input as object)
.filter(key => !extrasKeys.includes(key)) .filter(key => !extrasKeys.includes(key))
.forEach(key => { .forEach(key => {
moduleOptions[key] = input[key]; moduleOptions[key] = input[key];

View File

@@ -77,7 +77,7 @@ export class ParseEnumPipe<T = any> implements PipeTransform<T> {
} }
protected isEnum(value: T): boolean { protected isEnum(value: T): boolean {
const enumValues = Object.keys(this.enumType!).map( const enumValues = Object.keys(this.enumType as object).map(
item => this.enumType[item], item => this.enumType[item],
); );
return enumValues.includes(value); return enumValues.includes(value);

View File

@@ -215,7 +215,7 @@ export class ValidationPipe implements PipeTransform<any> {
} }
protected toEmptyIfNil<T = any, R = any>(value: T): R | object { protected toEmptyIfNil<T = any, R = any>(value: T): R | object {
return isNil(value) ? {} : value!; return isNil(value) ? {} : (value as object);
} }
protected stripProtoKeys(value: any) { protected stripProtoKeys(value: any) {

View File

@@ -365,7 +365,7 @@ export class Injector {
return item; return item;
}; };
return [ return [
wrapper.inject?.map?.(mapFactoryProviderInjectArray)!, wrapper.inject?.map?.(mapFactoryProviderInjectArray) as any[],
optionalDependenciesIds, optionalDependenciesIds,
]; ];
} }

View File

@@ -40,7 +40,7 @@ export class LazyModuleLoader {
moduleClassOrDynamicDefinition, moduleClassOrDynamicDefinition,
); );
const moduleInstance = this.modulesContainer.get(token)!; const moduleInstance = this.modulesContainer.get(token)!;
return moduleInstance && this.getTargetModuleRef(moduleInstance)!; return moduleInstance && this.getTargetModuleRef(moduleInstance);
} }
const lazyModulesContainer = const lazyModulesContainer =
this.createLazyModulesContainer(moduleInstances); this.createLazyModulesContainer(moduleInstances);

View File

@@ -219,7 +219,7 @@ export class GraphInspector {
targetClassName: target.name, targetClassName: target.name,
sourceClassToken: source.token, sourceClassToken: source.token,
targetClassToken: target.token, targetClassToken: target.token,
targetModuleName: target.host?.name!, targetModuleName: target.host?.name as string,
keyOrIndex, keyOrIndex,
injectionType, injectionType,
}, },

View File

@@ -338,7 +338,7 @@ export class MiddlewareModule<
} }
private getContextId(request: unknown, isTreeDurable: boolean): ContextId { private getContextId(request: unknown, isTreeDurable: boolean): ContextId {
const contextId = ContextIdFactory.getByRequest(request!); const contextId = ContextIdFactory.getByRequest(request as object);
if (!request![REQUEST_CONTEXT_ID]) { if (!request![REQUEST_CONTEXT_ID]) {
Object.defineProperty(request, REQUEST_CONTEXT_ID, { Object.defineProperty(request, REQUEST_CONTEXT_ID, {
value: contextId, value: contextId,

View File

@@ -112,8 +112,8 @@ export function isMiddlewareRouteExcluded(
if (excludedRoutes.length <= 0) { if (excludedRoutes.length <= 0) {
return false; return false;
} }
const reqMethod = httpAdapter.getRequestMethod?.(req)!; const reqMethod = httpAdapter.getRequestMethod!(req);
const originalUrl = httpAdapter.getRequestUrl?.(req)!; const originalUrl = httpAdapter.getRequestUrl!(req);
const queryParamsIndex = originalUrl ? originalUrl.indexOf('?') : -1; const queryParamsIndex = originalUrl ? originalUrl.indexOf('?') : -1;
const pathname = const pathname =
queryParamsIndex >= 0 queryParamsIndex >= 0

View File

@@ -115,7 +115,7 @@ export class ReplContext {
return typeof token !== 'string' return typeof token !== 'string'
? typeof token === 'function' ? typeof token === 'function'
? token.name ? token.name
: token?.toString()! : (token?.toString() as string)
: `"${token}"`; : `"${token}"`;
} }

View File

@@ -447,7 +447,7 @@ export class RouterExecutionContext {
result, result,
(res as any).raw || res, (res as any).raw || res,
(req as any).raw || req, (req as any).raw || req,
{ additionalHeaders: res.getHeaders?.()! }, { additionalHeaders: res.getHeaders!() },
); );
}; };
} }

View File

@@ -314,13 +314,13 @@ export class DependenciesScanner {
), ),
); );
methodInjectables.forEach(methodInjectable => { methodInjectables.forEach(methodInjectable => {
methodInjectable.metadata!.forEach(injectable => methodInjectable.metadata.forEach(injectable =>
this.insertInjectable( this.insertInjectable(
injectable, injectable,
token, token,
component, component,
ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey], ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey],
methodInjectable.methodKey!, methodInjectable.methodKey,
), ),
); );
}); });

View File

@@ -37,7 +37,7 @@ describe('provider classifier', () => {
it('should return false if provider is undefined', () => { it('should return false if provider is undefined', () => {
const classProvider = undefined!; const classProvider = undefined!;
expect(isClassProvider(classProvider as ClassProvider)!).to.be.false; expect(isClassProvider(classProvider)).to.be.false;
}); });
}); });

View File

@@ -78,7 +78,7 @@ export class ClientKafka
'No producer initialized. Please, call the "connect" method first.', 'No producer initialized. Please, call the "connect" method first.',
); );
} }
return this._producer!; return this._producer;
} }
constructor(protected readonly options: Required<KafkaOptions>['options']) { constructor(protected readonly options: Required<KafkaOptions>['options']) {

View File

@@ -20,8 +20,8 @@ let natsPackage = {} as any;
// type Client = import('nats').NatsConnection; // type Client = import('nats').NatsConnection;
// type NatsMsg = import('nats').Msg; // type NatsMsg = import('nats').Msg;
type Client = any; type Client = Record<string, any>;
type NatsMsg = any; type NatsMsg = Record<string, any>;
/** /**
* @publicApi * @publicApi
@@ -216,12 +216,12 @@ export class ClientNats extends ClientProxy<NatsEvents, NatsStatus> {
callback, callback,
); );
const subscription = this.natsClient.subscribe(inbox, { const subscription = this.natsClient!.subscribe(inbox, {
callback: subscriptionHandler, callback: subscriptionHandler,
}); });
const headers = this.mergeHeaders(serializedPacket.headers); const headers = this.mergeHeaders(serializedPacket.headers);
this.natsClient.publish(channel, serializedPacket.data, { this.natsClient!.publish(channel, serializedPacket.data, {
reply: inbox, reply: inbox,
headers, headers,
}); });
@@ -240,7 +240,7 @@ export class ClientNats extends ClientProxy<NatsEvents, NatsStatus> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
try { try {
this.natsClient.publish(pattern, serializedPacket.data, { this.natsClient!.publish(pattern, serializedPacket.data, {
headers, headers,
}); });
resolve(); resolve();

View File

@@ -198,7 +198,7 @@ export abstract class ClientProxy<
prop: Attribute, prop: Attribute,
defaultValue: DefaultValue = undefined as DefaultValue, defaultValue: DefaultValue = undefined as DefaultValue,
) { ) {
return obj && prop in obj ? obj![prop] : defaultValue; return obj && prop in obj ? (obj as any)[prop] : defaultValue;
} }
protected normalizePattern(pattern: MsPattern): string { protected normalizePattern(pattern: MsPattern): string {

View File

@@ -1,5 +1,3 @@
/* eslint-disable prefer-spread */
import { import {
ArgumentsHost, ArgumentsHost,
IntrinsicException, IntrinsicException,

View File

@@ -18,8 +18,9 @@ export class RpcException extends Error {
) { ) {
this.message = (this.error as Record<string, any>).message; this.message = (this.error as Record<string, any>).message;
} else if (this.constructor) { } else if (this.constructor) {
this.message = this.message = this.constructor.name
this.constructor!.name!.match(/[A-Z][a-z]+|[0-9]+/g)!.join(' '); .match(/[A-Z][a-z]+|[0-9]+/g)!
.join(' ');
} }
} }

View File

@@ -167,7 +167,7 @@ export class ListenersController {
{ {
type: 'microservice', type: 'microservice',
methodName: definition.methodKey, methodName: definition.methodKey,
className: instanceWrapper.metatype?.name!, className: instanceWrapper.metatype?.name as string,
classNodeId: instanceWrapper.id, classNodeId: instanceWrapper.id,
metadata: { metadata: {
key: definition.patterns.toString(), key: definition.patterns.toString(),

View File

@@ -32,7 +32,7 @@ export class ServerFactory {
case Transport.MQTT: case Transport.MQTT:
return new ServerMqtt(options as Required<MqttOptions>['options']); return new ServerMqtt(options as Required<MqttOptions>['options']);
case Transport.GRPC: case Transport.GRPC:
return new ServerGrpc(options as Required<GrpcOptions>['options']); return new ServerGrpc(options);
case Transport.KAFKA: case Transport.KAFKA:
return new ServerKafka(options as Required<KafkaOptions>['options']); return new ServerKafka(options as Required<KafkaOptions>['options']);
case Transport.RMQ: case Transport.RMQ:

View File

@@ -75,7 +75,7 @@ export class ServerRedis extends Server<RedisEvents, RedisStatus> {
} }
public start(callback?: () => void) { public start(callback?: () => void) {
Promise.all([this.subClient.connect(), this.pubClient.connect()]) void Promise.all([this.subClient.connect(), this.pubClient.connect()])
.then(() => { .then(() => {
this.bindEvents(this.subClient, this.pubClient); this.bindEvents(this.subClient, this.pubClient);
callback?.(); callback?.();

View File

@@ -219,7 +219,7 @@ export abstract class Server<
prop: Attribute, prop: Attribute,
defaultValue: DefaultValue = undefined as DefaultValue, defaultValue: DefaultValue = undefined as DefaultValue,
) { ) {
return obj && prop in obj ? obj![prop] : defaultValue; return obj && prop in obj ? (obj as any)[prop] : defaultValue;
} }
protected handleError(error: string) { protected handleError(error: string) {

View File

@@ -687,7 +687,7 @@ describe('ClientKafka', () => {
assignPacketIdStub = sinon assignPacketIdStub = sinon
.stub(client as any, 'assignPacketId') .stub(client as any, 'assignPacketId')
.callsFake(packet => .callsFake(packet =>
Object.assign(packet!, { Object.assign(packet as object, {
id: correlationId, id: correlationId,
}), }),
); );

View File

@@ -58,7 +58,7 @@ describe('ClientMqtt', () => {
connectSpy = sinon.stub(client, 'connect'); connectSpy = sinon.stub(client, 'connect');
assignStub = sinon assignStub = sinon
.stub(client, 'assignPacketId' as any) .stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet!, { id })); .callsFake(packet => Object.assign(packet as object, { id }));
}); });
afterEach(() => { afterEach(() => {
connectSpy.restore(); connectSpy.restore();

View File

@@ -88,7 +88,7 @@ describe('ClientNats', () => {
callback = sinon.spy(); callback = sinon.spy();
assignStub = sinon assignStub = sinon
.stub(client, 'assignPacketId' as any) .stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet!, { id })); .callsFake(packet => Object.assign(packet as object, { id }));
subscription = client['publish'](msg, callback); subscription = client['publish'](msg, callback);
subscription(); subscription();

View File

@@ -93,7 +93,7 @@ describe('ClientRedis', () => {
callback = sinon.spy(); callback = sinon.spy();
assignStub = sinon assignStub = sinon
.stub(client, 'assignPacketId' as any) .stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet!, { id })); .callsFake(packet => Object.assign(packet as object, { id }));
getReplyPatternStub = sinon getReplyPatternStub = sinon
.stub(client, 'getReplyPattern') .stub(client, 'getReplyPattern')

View File

@@ -176,16 +176,16 @@ describe('JsonSocket connection', () => {
server.once('connection', socket => { server.once('connection', socket => {
const serverSocket = new JsonSocket(socket); const serverSocket = new JsonSocket(socket);
serverSocket!.once('end', () => { serverSocket.once('end', () => {
setTimeout(() => { setTimeout(() => {
expect(serverSocket!['isClosed']).to.equal(true); expect(serverSocket['isClosed']).to.equal(true);
expect(clientSocket!['isClosed']).to.equal(true); expect(clientSocket['isClosed']).to.equal(true);
clientSocket!.on(TcpEventsMap.CONNECT, () => { clientSocket.on(TcpEventsMap.CONNECT, () => {
setTimeout(() => { setTimeout(() => {
expect(clientSocket!['isClosed']).to.equal(false); expect(clientSocket['isClosed']).to.equal(false);
clientSocket!.end(); clientSocket.end();
server.close(done); server.close(done);
}, 10); }, 10);
}); });
@@ -196,11 +196,11 @@ describe('JsonSocket connection', () => {
} }
const port2 = (address2 as AddressInfo).port; const port2 = (address2 as AddressInfo).port;
clientSocket!.connect(port2, ip); clientSocket.connect(port2, ip);
}, 10); }, 10);
}); });
clientSocket!.end(); clientSocket.end();
}); });
const address1 = server.address(); const address1 = server.address();
@@ -209,7 +209,7 @@ describe('JsonSocket connection', () => {
} }
const port1 = (address1 as AddressInfo).port; const port1 = (address1 as AddressInfo).port;
clientSocket!.connect(port1, ip); clientSocket.connect(port1, ip);
}); });
server.listen(); server.listen();
}); });

View File

@@ -393,9 +393,7 @@ describe('ServerKafka', () => {
await server.handleMessage(payload); await server.handleMessage(payload);
expect( expect(
getPublisherSpy.calledWith({ getPublisherSpy.calledWith({
id: payload.message!.headers![ id: payload.message.headers![KafkaHeaders.CORRELATION_ID]!.toString(),
KafkaHeaders.CORRELATION_ID
]!.toString(),
err: NO_MESSAGE_HANDLER, err: NO_MESSAGE_HANDLER,
}), }),
).to.be.true; ).to.be.true;
@@ -455,7 +453,7 @@ describe('ServerKafka', () => {
response: messageValue, response: messageValue,
}, },
replyTopic, replyTopic,
undefined!, '',
correlationId, correlationId,
); );

View File

@@ -268,7 +268,7 @@ export class ExpressAdapter extends AbstractHttpAdapter<
options?: Omit<Options, 'verify'>, options?: Omit<Options, 'verify'>,
): this { ): this {
const parserOptions = getBodyParserOptions<Options>(rawBody, options); const parserOptions = getBodyParserOptions<Options>(rawBody, options);
const parser = bodyparser[type](parserOptions!); const parser = bodyparser[type](parserOptions);
this.use(parser); this.use(parser);

View File

@@ -428,7 +428,7 @@ export class FastifyAdapter<
response.statusCode = statusCode; response.statusCode = statusCode;
return response; return response;
} }
return (response as TReply).code(statusCode); return (response as { code: Function }).code(statusCode);
} }
public end(response: TReply, message?: string) { public end(response: TReply, message?: string) {

View File

@@ -15,8 +15,9 @@ export class WsException extends Error {
) { ) {
this.message = (this.error as Record<string, any>).message; this.message = (this.error as Record<string, any>).message;
} else if (this.constructor) { } else if (this.constructor) {
this.message = this.message = this.constructor.name
this.constructor!.name!.match(/[A-Z][a-z]+|[0-9]+/g)!.join(' '); .match(/[A-Z][a-z]+|[0-9]+/g)!
.join(' ');
} }
} }