Skip to content

Commit 264be8d

Browse files
authored
Merge pull request #1697 from chappelo/unsafe-calls
remove @typescript-eslint/no-unsafe-call
2 parents e10185b + bba9735 commit 264be8d

File tree

29 files changed

+65
-41
lines changed

29 files changed

+65
-41
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module.exports = {
3131
],
3232
'@typescript-eslint/no-explicit-any': 'off',
3333
'@typescript-eslint/no-unsafe-assignment': 'off',
34-
'@typescript-eslint/no-unsafe-call': 'off',
3534
'@typescript-eslint/no-unsafe-argument': 'off',
3635
'@typescript-eslint/no-unsafe-member-access': 'off',
3736
'@typescript-eslint/no-unsafe-return': 'off',

packages/cli/src/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,11 @@ export async function generateSpecAndRoutes(args: SwaggerArgs, metadata?: Tsoa.M
397397
throw err;
398398
}
399399
}
400+
export type RouteGeneratorModule<Config extends ExtendedRoutesConfig> = {
401+
default: new (
402+
metadata: Tsoa.Metadata,
403+
routesConfig: Config,
404+
) => {
405+
GenerateCustomRoutes: () => Promise<void>;
406+
};
407+
};

packages/cli/src/module/generate-routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ts from 'typescript';
2-
import { ExtendedRoutesConfig } from '../cli';
2+
import { ExtendedRoutesConfig, RouteGeneratorModule } from '../cli';
33
import { MetadataGenerator } from '../metadataGeneration/metadataGenerator';
44
import { Tsoa } from '@tsoa/runtime';
55
import { DefaultRouteGenerator } from '../routeGeneration/defaultRouteGenerator';
@@ -46,12 +46,12 @@ async function getRouteGenerator<Config extends ExtendedRoutesConfig>(metadata:
4646
if (typeof routeGenerator === 'string') {
4747
try {
4848
// try as a module import
49-
const module = await import(routeGenerator);
49+
const module = (await import(routeGenerator)) as RouteGeneratorModule<Config>;
5050
return new module.default(metadata, routesConfig);
5151
} catch (_err) {
5252
// try to find a relative import path
5353
const relativePath = path.relative(__dirname, routeGenerator);
54-
const module = await import(relativePath);
54+
const module = (await import(relativePath)) as RouteGeneratorModule<Config>;
5555
return new module.default(metadata, routesConfig);
5656
}
5757
} else {

packages/cli/src/swagger/specGenerator2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export class SpecGenerator2 extends SpecGenerator {
6868

6969
if (this.config.spec) {
7070
this.config.specMerging = this.config.specMerging || 'immediate';
71-
const mergeFuncs: { [key: string]: any } = {
71+
const mergeFuncs: { [key: string]: (spec: UnspecifiedObject, merge: UnspecifiedObject) => UnspecifiedObject } = {
7272
immediate: Object.assign,
7373
recursive: mergeAnything,
7474
deepmerge: (spec: UnspecifiedObject, merge: UnspecifiedObject): UnspecifiedObject => deepMerge(spec, merge),
7575
};
7676

77-
spec = mergeFuncs[this.config.specMerging](spec, this.config.spec);
77+
spec = mergeFuncs[this.config.specMerging](spec as unknown as UnspecifiedObject, this.config.spec as unknown as UnspecifiedObject) as unknown as Swagger.Spec2;
7878
}
7979
if (this.config.schemes) {
8080
spec.schemes = this.config.schemes;

packages/cli/src/swagger/specGenerator3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ export class SpecGenerator3 extends SpecGenerator {
3939

4040
if (this.config.spec) {
4141
this.config.specMerging = this.config.specMerging || 'immediate';
42-
const mergeFuncs: { [key: string]: any } = {
42+
const mergeFuncs: { [key: string]: (spec: UnspecifiedObject, merge: UnspecifiedObject) => UnspecifiedObject } = {
4343
immediate: Object.assign,
4444
recursive: mergeAnything,
4545
deepmerge: (spec: UnspecifiedObject, merge: UnspecifiedObject): UnspecifiedObject => deepMerge(spec, merge),
4646
};
4747

48-
spec = mergeFuncs[this.config.specMerging](spec, this.config.spec);
48+
spec = mergeFuncs[this.config.specMerging](spec as unknown as UnspecifiedObject, this.config.spec as UnspecifiedObject) as unknown as Swagger.Spec3;
4949
}
5050

5151
return spec;

packages/runtime/src/routeGeneration/templates/express/expressTemplateService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FieldErrors } from '../../templateHelpers';
55
import { TsoaRoute } from '../../tsoa-route';
66
import { ValidateError } from '../../templateHelpers';
77
import { TemplateService } from '../templateService';
8+
import { Readable } from 'node:stream';
89

910
type ExpressApiHandlerParameters = {
1011
methodName: string;
@@ -115,7 +116,7 @@ export class ExpressTemplateService extends TemplateService<ExpressApiHandlerPar
115116
});
116117
if (data && typeof data.pipe === 'function' && data.readable && typeof data._read === 'function') {
117118
response.status(statusCode || 200);
118-
data.pipe(response);
119+
(data as Readable).pipe(response);
119120
} else if (data !== null && data !== undefined) {
120121
response.status(statusCode || 200).json(data);
121122
} else {

packages/runtime/src/routeGeneration/templates/templateService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ export abstract class TemplateService<ApiHandlerParameters, ValidationArgsParame
2626
protected buildPromise(methodName: string, controller: Controller | object, validatedArgs: any) {
2727
const prototype = Object.getPrototypeOf(controller);
2828
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
29-
return descriptor!.value.apply(controller, validatedArgs);
29+
return (descriptor!.value as () => Promise<PropertyDescriptor>).apply(controller, validatedArgs);
3030
}
3131
}

tests/esm/fixtures/express/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ app.use(bodyParser.json() as RequestHandler);
1313
app.use((req, res, next) => {
1414
methodOverride()(req, res, next);
1515
});
16-
app.use((req: any, res: any, next: any) => {
16+
app.use((req: any, res: any, next: express.NextFunction) => {
1717
req.stringValue = 'fancyStringForContext';
1818
next();
1919
});
20-
RegisterRoutes(app);
20+
(RegisterRoutes as (app: express.Express) => void)(app);
2121

2222
// It's important that this come after the main routes are registered
2323
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {

tests/fixtures/custom/custom-route-generator/serverlessRouteGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class ServerlessRouteGenerator extends AbstractRouteGenerator<Ser
7777
// This would need to generate a CDK "Stack" that takes the tsoa metadata as input and generates a valid serverless CDK infrastructure stack from template
7878
const templateFileName = this.options.stackTemplate;
7979
const fileName = `${this.options.routesDir}/stack.ts`;
80-
const context = this.buildContext() as unknown as any;
80+
const context = this.buildContext();
8181
context.controllers = context.controllers.map(controller => {
8282
controller.actions = controller.actions.map(action => {
8383
return {

tests/fixtures/custom/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ app.use(bodyParser.json());
2323
app.use((req, res, next) => {
2424
methodOverride()(req, res, next);
2525
});
26-
app.use((req: any, res: any, next: any) => {
26+
app.use((req: any, res: any, next: express.NextFunction) => {
2727
req.stringValue = 'fancyStringForContext';
2828
next();
2929
});
30-
RegisterRoutes(app);
30+
(RegisterRoutes as (app: express.Express) => void)(app);
3131

3232
// It's important that this come after the main routes are registered
3333
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {

0 commit comments

Comments
 (0)