Nswag: TypeScript --noUnusedParameters and --noUnusedLocals flags

Created on 22 Feb 2017  路  8Comments  路  Source: RicoSuter/NSwag

Hello, I am currently using tslint as a linter for my ts files and I was ignoring the ts file, generated by your awesome lib.
Now, tslint started to deprecate the unused varuable flag (Start to deprecate no-unused-variable rule) , because in newer versions of Typescript noUnusedParametersand noUnusedLocals flags have been added (Flag unused declarations with --noUnusedParameters and --noUnusedLocals)
If you set them to true and try to compile the ts file, generated by NSwag you will get _at least_:

  • error TS6133: 'caught' is declared but never used, when setting noUnusedParametersto true (caused by this)
  • error TS6133: 'RequestOptionsArgs' is declared but never used, when setting noUnusedLocals to true (caused by this)

As far as I can see the latest is caused, because it is used in the TransformOptionsMethod here

There might be some other errors, those are the onse I stumbled upon.
Thank you!

help wanted enhancement

Most helpful comment

@rsuter You can't disable validation currently because it's at the TypeScript compiler level.

I have some changes in a branch to solve the particular issues here, but I couldn't send a PR last night because of the diff problem.

We'll probably want to go through the other clients besides Angular 2 and check those as well.

All 8 comments

Good find, is there a way to completely disable validation for a .ts document (there is already a comment for TSLint)?

@rsuter You can't disable validation currently because it's at the TypeScript compiler level.

I have some changes in a branch to solve the particular issues here, but I couldn't send a PR last night because of the diff problem.

We'll probably want to go through the other clients besides Angular 2 and check those as well.

Yes, we should fix all tpls

@rsuter Yes, you can skip the validation with TSLint for some files, but you shouldn't bother with TSLint, mostly because its usage is optional and the usage of the TS compiler is required : )

As @grovesNL said, those flags are now part of the Typescript compiler itself. You can disasble the validation if you set them to false(the default values), but you can't disable them for some files. So It's either on or off for all of your ts files. As I said, and as @grovesNL pointed out, there might be some other problems (due to some other flags in the TS compiler config) and in other TS templates from(I posted this issue just for the Angular2 template).

We could start with min NSwag configuration, generate all of the possible TS templates and then run them with through the TS compiler with max _strictness_ options. Something like:

"compilerOptions": {
...
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
...
  }

I'll try to look at this soon. #563 is related to noImplicitAny too.

Maybe we should also improve the integration tests so that the generated TS outputs are compiled and linted... Currently I regenerate the integration svcs and only check the diff...

Can we close this one?

Very good job, @rsuter , @grovesNL . Thank you very much!

This issue is resolved, so you can close it now : )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

satyanarayan18 picture satyanarayan18  路  38Comments

Boriszn picture Boriszn  路  48Comments

robertsundstrom picture robertsundstrom  路  52Comments

ThaDaVos picture ThaDaVos  路  24Comments

georgeonofrei picture georgeonofrei  路  24Comments