mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 15:08:37 +00:00
build: use strict null checks part 5
This commit is contained in:
@@ -4,6 +4,7 @@ import * as chaiAsPromised from 'chai-as-promised';
|
||||
import * as sinon from 'sinon';
|
||||
import { BarService } from '../src/bar.service';
|
||||
import { FooService } from '../src/foo.service';
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
const { expect } = chai;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -17,17 +17,17 @@ export class WebhooksExplorer {
|
||||
const { name } = this.discoveryService.getMetadataByDecorator(
|
||||
Webhook,
|
||||
wrapper,
|
||||
);
|
||||
)!;
|
||||
return {
|
||||
name,
|
||||
handlers: this.metadataScanner
|
||||
.getAllMethodNames(wrapper.metatype.prototype)
|
||||
.getAllMethodNames(wrapper.metatype!.prototype)
|
||||
.map(methodName => {
|
||||
const { event } = this.discoveryService.getMetadataByDecorator(
|
||||
WebhookHandler,
|
||||
wrapper,
|
||||
methodName,
|
||||
);
|
||||
)!;
|
||||
return {
|
||||
methodName,
|
||||
event,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -20,6 +20,6 @@ export class CatsRequestScopedService {
|
||||
}
|
||||
|
||||
findOneById(id: number): Cat {
|
||||
return this.cats.find(cat => cat.id === id);
|
||||
return this.cats.find(cat => cat.id === id)!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@ export class CatsService {
|
||||
}
|
||||
|
||||
findOneById(id: number): Cat {
|
||||
return this.cats.find(cat => cat.id === id);
|
||||
return this.cats.find(cat => cat.id === id)!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -6,7 +6,7 @@ export class CircularModule {
|
||||
const a = {
|
||||
module: CircularModule,
|
||||
providers: [InputService],
|
||||
b: null,
|
||||
b: null as any,
|
||||
};
|
||||
a.b = a;
|
||||
return a;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -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?
|
||||
for (const topic of topicMetadata.topics) {
|
||||
if (topic.partitions.length < numbersOfServers) {
|
||||
|
||||
@@ -123,7 +123,7 @@ describe.skip('Kafka transport', function () {
|
||||
});
|
||||
|
||||
it(`/POST (sync command create user) Concurrency Test`, async () => {
|
||||
const promises = [];
|
||||
const promises = [] as Array<Promise<any>>;
|
||||
for (let concurrencyKey = 0; concurrencyKey < 100; concurrencyKey++) {
|
||||
const innerUserDto = JSON.parse(JSON.stringify(userDto));
|
||||
innerUserDto.name += `+${concurrencyKey}`;
|
||||
|
||||
@@ -17,7 +17,7 @@ import { SumDto } from './dto/sum.dto';
|
||||
*/
|
||||
const explicitPartitioner = () => {
|
||||
return ({ message }: PartitionerArgs) => {
|
||||
return parseFloat(message.headers.toPartition.toString());
|
||||
return parseFloat(message.headers!.toPartition!.toString());
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ export class MqttController {
|
||||
}
|
||||
|
||||
@MessagePattern('wildcard-message/#')
|
||||
wildcardMessageHandler(data: number[]): number {
|
||||
wildcardMessageHandler(data: number[]): number | undefined {
|
||||
if ((data as any).response) {
|
||||
return;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ export class MqttController {
|
||||
}
|
||||
|
||||
@MessagePattern('$share/test-group/shared-wildcard-message/#')
|
||||
sharedWildcardMessageHandler(data: number[]): number {
|
||||
sharedWildcardMessageHandler(data: number[]): number | undefined {
|
||||
if ((data as any).response) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"outDir": "./dist",
|
||||
"strictNullChecks": true,
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../../packages/common"],
|
||||
"@nestjs/common/*": ["../../../packages/common/*"],
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"outDir": "./dist",
|
||||
"strictNullChecks": true,
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../../packages/common"],
|
||||
"@nestjs/common/*": ["../../../packages/common/*"],
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"outDir": "./dist",
|
||||
"strictNullChecks": true,
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../../packages/common"],
|
||||
"@nestjs/common/*": ["../../../packages/common/*"],
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"outDir": "./dist",
|
||||
"strictNullChecks": true,
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../../packages/common"],
|
||||
"@nestjs/common/*": ["../../../packages/common/*"],
|
||||
|
||||
@@ -7,7 +7,7 @@ export class ExpressController {
|
||||
getRawBody(@Req() req: RawBodyRequest<Request>) {
|
||||
return {
|
||||
parsed: req.body,
|
||||
raw: req.rawBody.toString(),
|
||||
raw: req.rawBody!.toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export class FastifyController {
|
||||
getRawBody(@Req() req: RawBodyRequest<FastifyRequest>) {
|
||||
return {
|
||||
parsed: req.body,
|
||||
raw: req.rawBody.toString(),
|
||||
raw: req.rawBody!.toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"outDir": "./dist",
|
||||
"strictNullChecks": true,
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../../packages/common"],
|
||||
"@nestjs/common/*": ["../../../packages/common/*"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -9,7 +9,7 @@ export class DurableContextIdStrategy implements ContextIdStrategy {
|
||||
let tenantSubTreeId: ContextId;
|
||||
|
||||
if (tenants.has(tenantId)) {
|
||||
tenantSubTreeId = tenants.get(tenantId);
|
||||
tenantSubTreeId = tenants.get(tenantId)!;
|
||||
} else {
|
||||
tenantSubTreeId = { id: +tenantId } as ContextId;
|
||||
tenants.set(tenantId, tenantSubTreeId);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class Guard implements CanActivate {
|
||||
static COUNTER = 0;
|
||||
static REQUEST_SCOPED_DATA = [];
|
||||
static REQUEST_SCOPED_DATA = [] as number[];
|
||||
|
||||
constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
|
||||
Guard.COUNTER++;
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class Interceptor implements NestInterceptor {
|
||||
static COUNTER = 0;
|
||||
static REQUEST_SCOPED_DATA = [];
|
||||
static REQUEST_SCOPED_DATA = [] as number[];
|
||||
|
||||
constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
|
||||
Interceptor.COUNTER++;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { UsersService } from './users.service';
|
||||
@Injectable()
|
||||
export class UserByIdPipe implements PipeTransform<string> {
|
||||
static COUNTER = 0;
|
||||
static REQUEST_SCOPED_DATA = [];
|
||||
static REQUEST_SCOPED_DATA = [] as number[];
|
||||
|
||||
constructor(
|
||||
@Inject('REQUEST_ID') private readonly requestId: number,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class Guard implements CanActivate {
|
||||
static COUNTER = 0;
|
||||
static REQUEST_SCOPED_DATA = [];
|
||||
static REQUEST_SCOPED_DATA = [] as number[];
|
||||
|
||||
constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
|
||||
Guard.COUNTER++;
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class Interceptor implements NestInterceptor {
|
||||
static COUNTER = 0;
|
||||
static REQUEST_SCOPED_DATA = [];
|
||||
static REQUEST_SCOPED_DATA = [] as number[];
|
||||
|
||||
constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
|
||||
Interceptor.COUNTER++;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('Custom Versioning (fastify)', () => {
|
||||
.flatMap(v => v.split(','))
|
||||
.map(header => header.match(/v(\d+\.?\d*)\+json$/))
|
||||
.filter(match => match && match.length)
|
||||
.map(matchArray => matchArray[1])
|
||||
.map(matchArray => matchArray![1])
|
||||
.sort()
|
||||
.reverse();
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ describe('Custom Versioning', () => {
|
||||
?.split(',')
|
||||
.map(header => header.match(/v(\d+\.?\d*)\+json$/))
|
||||
.filter(match => match && match.length)
|
||||
.map(matchArray => matchArray[1])
|
||||
.map(matchArray => matchArray![1])
|
||||
.sort()
|
||||
.reverse();
|
||||
|
||||
return versions;
|
||||
return versions!;
|
||||
};
|
||||
let app: INestApplication;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('ErrorGateway', () => {
|
||||
const testingModule = await Test.createTestingModule({
|
||||
providers: [ErrorGateway],
|
||||
}).compile();
|
||||
|
||||
|
||||
app = testingModule.createNestApplication();
|
||||
await app.listen(3000);
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@nestjs/common": ["../../packages/common"],
|
||||
|
||||
@@ -139,7 +139,7 @@ export class HttpException extends IntrinsicException {
|
||||
|
||||
if (isString(arg0) || Array.isArray(arg0) || isNumber(arg0)) {
|
||||
return {
|
||||
message: arg0!,
|
||||
message: arg0,
|
||||
error: arg1 as string,
|
||||
statusCode: statusCode!,
|
||||
};
|
||||
@@ -153,7 +153,7 @@ export class HttpException extends IntrinsicException {
|
||||
): string {
|
||||
return isString(descriptionOrOptions)
|
||||
? descriptionOrOptions
|
||||
: descriptionOrOptions?.description!;
|
||||
: (descriptionOrOptions?.description as string);
|
||||
}
|
||||
|
||||
public static getHttpExceptionOptionsFrom(
|
||||
|
||||
@@ -269,7 +269,7 @@ export class ConfigurableModuleBuilder<
|
||||
const moduleOptions = {};
|
||||
const extrasKeys = Object.keys(extras);
|
||||
|
||||
Object.keys(input!)
|
||||
Object.keys(input as object)
|
||||
.filter(key => !extrasKeys.includes(key))
|
||||
.forEach(key => {
|
||||
moduleOptions[key] = input[key];
|
||||
|
||||
@@ -77,7 +77,7 @@ export class ParseEnumPipe<T = any> implements PipeTransform<T> {
|
||||
}
|
||||
|
||||
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],
|
||||
);
|
||||
return enumValues.includes(value);
|
||||
|
||||
@@ -215,7 +215,7 @@ export class ValidationPipe implements PipeTransform<any> {
|
||||
}
|
||||
|
||||
protected toEmptyIfNil<T = any, R = any>(value: T): R | object {
|
||||
return isNil(value) ? {} : value!;
|
||||
return isNil(value) ? {} : (value as object);
|
||||
}
|
||||
|
||||
protected stripProtoKeys(value: any) {
|
||||
|
||||
@@ -365,7 +365,7 @@ export class Injector {
|
||||
return item;
|
||||
};
|
||||
return [
|
||||
wrapper.inject?.map?.(mapFactoryProviderInjectArray)!,
|
||||
wrapper.inject?.map?.(mapFactoryProviderInjectArray) as any[],
|
||||
optionalDependenciesIds,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export class LazyModuleLoader {
|
||||
moduleClassOrDynamicDefinition,
|
||||
);
|
||||
const moduleInstance = this.modulesContainer.get(token)!;
|
||||
return moduleInstance && this.getTargetModuleRef(moduleInstance)!;
|
||||
return moduleInstance && this.getTargetModuleRef(moduleInstance);
|
||||
}
|
||||
const lazyModulesContainer =
|
||||
this.createLazyModulesContainer(moduleInstances);
|
||||
|
||||
@@ -219,7 +219,7 @@ export class GraphInspector {
|
||||
targetClassName: target.name,
|
||||
sourceClassToken: source.token,
|
||||
targetClassToken: target.token,
|
||||
targetModuleName: target.host?.name!,
|
||||
targetModuleName: target.host?.name as string,
|
||||
keyOrIndex,
|
||||
injectionType,
|
||||
},
|
||||
|
||||
@@ -338,7 +338,7 @@ export class MiddlewareModule<
|
||||
}
|
||||
|
||||
private getContextId(request: unknown, isTreeDurable: boolean): ContextId {
|
||||
const contextId = ContextIdFactory.getByRequest(request!);
|
||||
const contextId = ContextIdFactory.getByRequest(request as object);
|
||||
if (!request![REQUEST_CONTEXT_ID]) {
|
||||
Object.defineProperty(request, REQUEST_CONTEXT_ID, {
|
||||
value: contextId,
|
||||
|
||||
@@ -112,8 +112,8 @@ export function isMiddlewareRouteExcluded(
|
||||
if (excludedRoutes.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
const reqMethod = httpAdapter.getRequestMethod?.(req)!;
|
||||
const originalUrl = httpAdapter.getRequestUrl?.(req)!;
|
||||
const reqMethod = httpAdapter.getRequestMethod!(req);
|
||||
const originalUrl = httpAdapter.getRequestUrl!(req);
|
||||
const queryParamsIndex = originalUrl ? originalUrl.indexOf('?') : -1;
|
||||
const pathname =
|
||||
queryParamsIndex >= 0
|
||||
|
||||
@@ -115,7 +115,7 @@ export class ReplContext {
|
||||
return typeof token !== 'string'
|
||||
? typeof token === 'function'
|
||||
? token.name
|
||||
: token?.toString()!
|
||||
: (token?.toString() as string)
|
||||
: `"${token}"`;
|
||||
}
|
||||
|
||||
|
||||
@@ -447,7 +447,7 @@ export class RouterExecutionContext {
|
||||
result,
|
||||
(res as any).raw || res,
|
||||
(req as any).raw || req,
|
||||
{ additionalHeaders: res.getHeaders?.()! },
|
||||
{ additionalHeaders: res.getHeaders!() },
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -314,13 +314,13 @@ export class DependenciesScanner {
|
||||
),
|
||||
);
|
||||
methodInjectables.forEach(methodInjectable => {
|
||||
methodInjectable.metadata!.forEach(injectable =>
|
||||
methodInjectable.metadata.forEach(injectable =>
|
||||
this.insertInjectable(
|
||||
injectable,
|
||||
token,
|
||||
component,
|
||||
ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey],
|
||||
methodInjectable.methodKey!,
|
||||
methodInjectable.methodKey,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('provider classifier', () => {
|
||||
it('should return false if provider is undefined', () => {
|
||||
const classProvider = undefined!;
|
||||
|
||||
expect(isClassProvider(classProvider as ClassProvider)!).to.be.false;
|
||||
expect(isClassProvider(classProvider)).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ export class ClientKafka
|
||||
'No producer initialized. Please, call the "connect" method first.',
|
||||
);
|
||||
}
|
||||
return this._producer!;
|
||||
return this._producer;
|
||||
}
|
||||
|
||||
constructor(protected readonly options: Required<KafkaOptions>['options']) {
|
||||
|
||||
@@ -20,8 +20,8 @@ let natsPackage = {} as any;
|
||||
// type Client = import('nats').NatsConnection;
|
||||
// type NatsMsg = import('nats').Msg;
|
||||
|
||||
type Client = any;
|
||||
type NatsMsg = any;
|
||||
type Client = Record<string, any>;
|
||||
type NatsMsg = Record<string, any>;
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
@@ -216,12 +216,12 @@ export class ClientNats extends ClientProxy<NatsEvents, NatsStatus> {
|
||||
callback,
|
||||
);
|
||||
|
||||
const subscription = this.natsClient.subscribe(inbox, {
|
||||
const subscription = this.natsClient!.subscribe(inbox, {
|
||||
callback: subscriptionHandler,
|
||||
});
|
||||
|
||||
const headers = this.mergeHeaders(serializedPacket.headers);
|
||||
this.natsClient.publish(channel, serializedPacket.data, {
|
||||
this.natsClient!.publish(channel, serializedPacket.data, {
|
||||
reply: inbox,
|
||||
headers,
|
||||
});
|
||||
@@ -240,7 +240,7 @@ export class ClientNats extends ClientProxy<NatsEvents, NatsStatus> {
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
this.natsClient.publish(pattern, serializedPacket.data, {
|
||||
this.natsClient!.publish(pattern, serializedPacket.data, {
|
||||
headers,
|
||||
});
|
||||
resolve();
|
||||
|
||||
@@ -198,7 +198,7 @@ export abstract class ClientProxy<
|
||||
prop: Attribute,
|
||||
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 {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
/* eslint-disable prefer-spread */
|
||||
import {
|
||||
ArgumentsHost,
|
||||
IntrinsicException,
|
||||
|
||||
@@ -18,8 +18,9 @@ export class RpcException extends Error {
|
||||
) {
|
||||
this.message = (this.error as Record<string, any>).message;
|
||||
} else if (this.constructor) {
|
||||
this.message =
|
||||
this.constructor!.name!.match(/[A-Z][a-z]+|[0-9]+/g)!.join(' ');
|
||||
this.message = this.constructor.name
|
||||
.match(/[A-Z][a-z]+|[0-9]+/g)!
|
||||
.join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ export class ListenersController {
|
||||
{
|
||||
type: 'microservice',
|
||||
methodName: definition.methodKey,
|
||||
className: instanceWrapper.metatype?.name!,
|
||||
className: instanceWrapper.metatype?.name as string,
|
||||
classNodeId: instanceWrapper.id,
|
||||
metadata: {
|
||||
key: definition.patterns.toString(),
|
||||
|
||||
@@ -32,7 +32,7 @@ export class ServerFactory {
|
||||
case Transport.MQTT:
|
||||
return new ServerMqtt(options as Required<MqttOptions>['options']);
|
||||
case Transport.GRPC:
|
||||
return new ServerGrpc(options as Required<GrpcOptions>['options']);
|
||||
return new ServerGrpc(options);
|
||||
case Transport.KAFKA:
|
||||
return new ServerKafka(options as Required<KafkaOptions>['options']);
|
||||
case Transport.RMQ:
|
||||
|
||||
@@ -75,7 +75,7 @@ export class ServerRedis extends Server<RedisEvents, RedisStatus> {
|
||||
}
|
||||
|
||||
public start(callback?: () => void) {
|
||||
Promise.all([this.subClient.connect(), this.pubClient.connect()])
|
||||
void Promise.all([this.subClient.connect(), this.pubClient.connect()])
|
||||
.then(() => {
|
||||
this.bindEvents(this.subClient, this.pubClient);
|
||||
callback?.();
|
||||
|
||||
@@ -219,7 +219,7 @@ export abstract class Server<
|
||||
prop: Attribute,
|
||||
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) {
|
||||
|
||||
@@ -687,7 +687,7 @@ describe('ClientKafka', () => {
|
||||
assignPacketIdStub = sinon
|
||||
.stub(client as any, 'assignPacketId')
|
||||
.callsFake(packet =>
|
||||
Object.assign(packet!, {
|
||||
Object.assign(packet as object, {
|
||||
id: correlationId,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('ClientMqtt', () => {
|
||||
connectSpy = sinon.stub(client, 'connect');
|
||||
assignStub = sinon
|
||||
.stub(client, 'assignPacketId' as any)
|
||||
.callsFake(packet => Object.assign(packet!, { id }));
|
||||
.callsFake(packet => Object.assign(packet as object, { id }));
|
||||
});
|
||||
afterEach(() => {
|
||||
connectSpy.restore();
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('ClientNats', () => {
|
||||
callback = sinon.spy();
|
||||
assignStub = sinon
|
||||
.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();
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('ClientRedis', () => {
|
||||
callback = sinon.spy();
|
||||
assignStub = sinon
|
||||
.stub(client, 'assignPacketId' as any)
|
||||
.callsFake(packet => Object.assign(packet!, { id }));
|
||||
.callsFake(packet => Object.assign(packet as object, { id }));
|
||||
|
||||
getReplyPatternStub = sinon
|
||||
.stub(client, 'getReplyPattern')
|
||||
|
||||
@@ -176,16 +176,16 @@ describe('JsonSocket connection', () => {
|
||||
server.once('connection', socket => {
|
||||
const serverSocket = new JsonSocket(socket);
|
||||
|
||||
serverSocket!.once('end', () => {
|
||||
serverSocket.once('end', () => {
|
||||
setTimeout(() => {
|
||||
expect(serverSocket!['isClosed']).to.equal(true);
|
||||
expect(clientSocket!['isClosed']).to.equal(true);
|
||||
expect(serverSocket['isClosed']).to.equal(true);
|
||||
expect(clientSocket['isClosed']).to.equal(true);
|
||||
|
||||
clientSocket!.on(TcpEventsMap.CONNECT, () => {
|
||||
clientSocket.on(TcpEventsMap.CONNECT, () => {
|
||||
setTimeout(() => {
|
||||
expect(clientSocket!['isClosed']).to.equal(false);
|
||||
expect(clientSocket['isClosed']).to.equal(false);
|
||||
|
||||
clientSocket!.end();
|
||||
clientSocket.end();
|
||||
server.close(done);
|
||||
}, 10);
|
||||
});
|
||||
@@ -196,11 +196,11 @@ describe('JsonSocket connection', () => {
|
||||
}
|
||||
const port2 = (address2 as AddressInfo).port;
|
||||
|
||||
clientSocket!.connect(port2, ip);
|
||||
clientSocket.connect(port2, ip);
|
||||
}, 10);
|
||||
});
|
||||
|
||||
clientSocket!.end();
|
||||
clientSocket.end();
|
||||
});
|
||||
|
||||
const address1 = server.address();
|
||||
@@ -209,7 +209,7 @@ describe('JsonSocket connection', () => {
|
||||
}
|
||||
const port1 = (address1 as AddressInfo).port;
|
||||
|
||||
clientSocket!.connect(port1, ip);
|
||||
clientSocket.connect(port1, ip);
|
||||
});
|
||||
server.listen();
|
||||
});
|
||||
|
||||
@@ -393,9 +393,7 @@ describe('ServerKafka', () => {
|
||||
await server.handleMessage(payload);
|
||||
expect(
|
||||
getPublisherSpy.calledWith({
|
||||
id: payload.message!.headers![
|
||||
KafkaHeaders.CORRELATION_ID
|
||||
]!.toString(),
|
||||
id: payload.message.headers![KafkaHeaders.CORRELATION_ID]!.toString(),
|
||||
err: NO_MESSAGE_HANDLER,
|
||||
}),
|
||||
).to.be.true;
|
||||
@@ -455,7 +453,7 @@ describe('ServerKafka', () => {
|
||||
response: messageValue,
|
||||
},
|
||||
replyTopic,
|
||||
undefined!,
|
||||
'',
|
||||
correlationId,
|
||||
);
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ export class ExpressAdapter extends AbstractHttpAdapter<
|
||||
options?: Omit<Options, 'verify'>,
|
||||
): this {
|
||||
const parserOptions = getBodyParserOptions<Options>(rawBody, options);
|
||||
const parser = bodyparser[type](parserOptions!);
|
||||
const parser = bodyparser[type](parserOptions);
|
||||
|
||||
this.use(parser);
|
||||
|
||||
|
||||
@@ -428,7 +428,7 @@ export class FastifyAdapter<
|
||||
response.statusCode = statusCode;
|
||||
return response;
|
||||
}
|
||||
return (response as TReply).code(statusCode);
|
||||
return (response as { code: Function }).code(statusCode);
|
||||
}
|
||||
|
||||
public end(response: TReply, message?: string) {
|
||||
|
||||
@@ -15,8 +15,9 @@ export class WsException extends Error {
|
||||
) {
|
||||
this.message = (this.error as Record<string, any>).message;
|
||||
} else if (this.constructor) {
|
||||
this.message =
|
||||
this.constructor!.name!.match(/[A-Z][a-z]+|[0-9]+/g)!.join(' ');
|
||||
this.message = this.constructor.name
|
||||
.match(/[A-Z][a-z]+|[0-9]+/g)!
|
||||
.join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user