Skip to content

Commit

Permalink
Merge pull request #1155 from jbpionnier/refactor_clean_as_any
Browse files Browse the repository at this point in the history
refactor(nestjs) code style, clean "as any"
  • Loading branch information
kamilmysliwiec committed Oct 5, 2018
2 parents 3e851e5 + 8a827ff commit 85d7384
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/common/cache/cache.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createCacheManager(): Provider {
const cacheManager = loadPackage('cache-manager', 'CacheModule');
const memoryCache = cacheManager.caching({
...defaultCacheOptions,
...((options || {}) as any),
...(options || {}),
});
return memoryCache;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function createParamDecorator(
index,
factory,
paramData,
...((paramPipes as any) as PipeTransform[]),
...(paramPipes as PipeTransform[]),
),
target.constructor,
key,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/cache/cache.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('CacheModule', () => {
const options = {
test: 'test',
};
const dynamicModule = CacheModule.register(options as any);
const dynamicModule = CacheModule.register(options);

expect(dynamicModule.providers).to.have.length(1);
expect(dynamicModule.imports).to.be.empty;
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/pipes/parse-int.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ describe('ParseIntPipe', () => {
describe('when validation passes', () => {
it('should return number', async () => {
const num = '3';
expect(await target.transform(num, {} as any)).to.equal(
expect(await target.transform(num, {} as ArgumentMetadata)).to.equal(
parseInt(num, 10),
);
});
});
describe('when validation fails', () => {
it('should throw an error', async () => {
return expect(target.transform('123abc', {} as any)).to.be.rejected;
return expect(target.transform('123abc', {} as ArgumentMetadata)).to.be.rejected;
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/core/adapters/express-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ export class ExpressAdapter implements HttpServer {
}

setErrorHandler(handler: Function) {
return this.use(handler as any);
return this.use(handler);
}

setNotFoundHandler(handler: Function) {
return this.use(handler as any);
return this.use(handler);
}

setHeader(response, name: string, value: string) {
return response.set(name, value);
}

getHttpServer<T = any>(): T {
return this.httpServer as any as T;
return this.httpServer as T;
}

setHttpServer(httpServer) {
this.httpServer = httpServer;
}

getInstance<T = any>(): T {
return this.instance as any as T;
return this.instance as T;
}

close() {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/adapters/fastify-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export class FastifyAdapter {
}

getHttpServer<T = any>(): T {
return this.instance.server as any as T;
return this.instance.server as T;
}

getInstance<T = any>(): T {
return this.instance as any as T;
return this.instance as T;
}

register(...args) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/exceptions/base-exception-filter-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class BaseExceptionFilterContext extends ContextCreator {
if (!module) {
return undefined;
}
return module.injectables.get((filter as any).name);
return module.injectables.get(filter.name);
}

public reflectCatchExceptions(instance: ExceptionFilter): Type<any>[] {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/exceptions/base-exception-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BaseExceptionFilter<T = any> implements ExceptionFilter<T> {
exception.stack,
);
}
return BaseExceptionFilter.logger.error(exception as any);
return BaseExceptionFilter.logger.error(exception);
}
const res = exception.getResponse();
const message = isObject(res)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/guards/guards-context-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class GuardsContextCreator extends ContextCreator {
if (!module) {
return undefined;
}
return module.injectables.get((guard as any).name);
return module.injectables.get(guard.name);
}

public getGlobalMetadata<T extends any[]>(): T {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/interceptors/interceptors-context-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class InterceptorsContextCreator extends ContextCreator {
if (!module) {
return undefined;
}
return module.injectables.get((metatype as any).name);
return module.injectables.get(metatype.name);
}

public getGlobalMetadata<T extends any[]>(): T {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/nest-application-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NestApplicationContext extends ModuleRef
const moduleMetatype = this.contextModule.metatype;
const scope = this.scope.concat(moduleMetatype);

const token = this.moduleTokenFactory.create(module as any, scope);
const token = this.moduleTokenFactory.create(module, scope);
const selectedModule = modules.get(token);
if (!selectedModule) {
throw new UnknownModuleException();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/nest-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export class NestApplication extends NestApplicationContext

const applicationConfig = new ApplicationConfig();
const instance = new NestMicroservice(
this.container as any,
options as any,
this.container,
options,
applicationConfig,
);
instance.registerListeners();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/nest-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class NestFactoryStatic {
this.applyLogger(options);
await this.initialize(module, container, applicationConfig);
return this.createNestInstance<INestMicroservice>(
new NestMicroservice(container, options as any, applicationConfig),
new NestMicroservice(container, options, applicationConfig),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/pipes/pipes-context-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PipesContextCreator extends ContextCreator {
if (!module) {
return undefined;
}
return module.injectables.get((metatype as any).name);
return module.injectables.get(metatype.name);
}

public getGlobalMetadata<T extends any[]>(): T {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/router/routes-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class RoutesResolver implements Resolver {
};
const handler = this.routerExceptionsFilter.create(
{},
callback as any,
callback,
undefined,
);
const proxy = this.routerProxy.createProxy(callback, handler);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/injector/module-token-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('ModuleTokenFactory', () => {
class Module {}
it('should force global scope when it is not set', () => {
const scope = 'global';
const token = factory.create(Module as any, [Module as any], undefined);
const token = factory.create(Module as any, [Module], undefined);
expect(token).to.be.deep.eq(
hash({
module: Module.name,
Expand All @@ -25,7 +25,7 @@ describe('ModuleTokenFactory', () => {
it('should returns expected token', () => {
const token = factory.create(
SingleScope()(Module) as any,
[Module as any],
[Module],
undefined,
);
expect(token).to.be.deep.eq(
Expand All @@ -39,7 +39,7 @@ describe('ModuleTokenFactory', () => {
it('should include dynamic metadata', () => {
const token = factory.create(
SingleScope()(Module) as any,
[Module as any],
[Module],
{
components: [{}],
} as any,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/middleware/middlewares-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('MiddlewareModule', () => {

const container = new MiddlewareContainer();
const moduleKey = 'Test' as any;
container.addConfig([configuration as any], moduleKey);
container.addConfig([configuration], moduleKey);

const instance = new InvalidMiddleware();
container.getMiddleware(moduleKey).set('InvalidMiddleware', {
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/client/client-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export abstract class ClientProxy {
prop: keyof T['options'],
defaultValue = undefined,
) {
return obj ? obj[prop as any] : defaultValue;
return obj ? obj[prop as string] : defaultValue;
}

protected normalizePattern<T = any>(pattern: T): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/server/server-nats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ServerNats extends Server implements CustomTransportStrategy {
public createNatsClient(): Client {
const options = this.options || ({} as NatsOptions);
return natsPackage.connect({
...(options as any),
...options,
url: this.url,
json: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export abstract class Server {
prop: keyof T['options'],
defaultValue = undefined,
) {
return obj ? obj[prop as any] : defaultValue;
return obj ? obj[prop as string] : defaultValue;
}

protected handleError(error: string) {
Expand Down

0 comments on commit 85d7384

Please sign in to comment.