microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.08k stars 12.49k forks source link

Typescript Unable to resolve signature of parameter of decorator in vscode #52396

Closed luluhoc closed 1 year ago

luluhoc commented 1 year ago

I'm getting the error when I'm decorating the class in nestjs service. I'm using typescript 4.9.4

The Typescript is compiling without errors, and I'm getting this problem only in VSCode.

Unable to resolve signature of parameter decorator when called as an expression.
  Argument of type 'undefined' is not assignable to parameter of type 'string | symbol'.ts(1239)

My tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "strictNullChecks": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2020",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
  }
}

My Class

export class AuthService {
  private readonly logger = new Logger('AuthService');
  constructor(
    private readonly jwtService: JwtService,
    private readonly prisma: PrismaService,
    private readonly passwordService: PasswordService,
    private readonly configService: ConfigService,
    private readonly twilioService: TwilioService,
    private readonly userService: UsersService,
    @InjectQueue('nest-worker') private nestWorkerQueue: Queue,
    @InjectQueue('mailsend') private mailSend: Queue,
    @Inject(CACHE_MANAGER) protected readonly cacheManager: Cache,
    private readonly mailerService: MailService
  ) {}

I tried reinstalling typescript and removing node modules, but the problem persists.

luluhoc commented 1 year ago

so the problem is JavaScript and TypeScript Nightly extension in VSCODE, when disabled the problem is gone.

luluhoc commented 1 year ago

https://github.com/microsoft/vscode-typescript-next/issues/72

wayn3r commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

magnocarvalho commented 1 year ago

@wayn3r Thanks, run TypeScript: Select TypeScript version and it worked for me. ✌️

izakharov commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

Thanks!! you saved my day 🙌

RyanCavanaugh commented 1 year ago

To expedite the triage process, we need everyone to follow the issue template and instructions.

When you clicked "Create New Issue", the issue form was pre-populated with a template and some instructions. We need you to read those instructions completely, follow them, and then fill in all the fields in that template.

We are not able to assist with issues that don't follow the template instructions as they represent a significantly larger amount of work compared to issues which are correctly specified. Thank you for understanding.

gggabop commented 1 year ago

Thanks for the solution bro;)

MarleeG commented 1 year ago

Thank you @izakharov !

jack-useb commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

That definitely saved my day 👍 Thank you! @wayn3r

parkchoongho commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

@wayn3r Thanks!! 👍👍

CRISTIAN-MULLER commented 1 year ago

https://github.com/microsoft/TypeScript/issues/52396#issuecomment-1404056467

@wayn3r You Rock.

std4453 commented 1 year ago

The underlying issue is still not fixed though, and it might come as a problem for someone who need to use TypeScript 5.0+. @luluhoc can you open a new issue following the issue template?

NabeelTariq44 commented 1 year ago

It's showing the same error to me TS1239: Unable to resolve signature of parameter decorator when called as an expression. Argument of type 'undefined' is not assignable to parameter of type 'string | symbol'.

Capture
sublimator commented 1 year ago

Something to do with the new decorators I suppose. I am also seeing this issue when trying to upgrade to TS5.
We are using experimental decorators.

Another missing functionality are parameter decorators. These are decorators with which method or constructor parameters can be decorated. This is a feature used by libraries like Angular, Nest.js, or type-graphql. As of shortly before the TypeScript 5 release, there are no separate proposals for this and no implementation in TypeScript. Because of this, Angular will not yet switch to the new decorators, but will continue using the experimental decorators, since the dependency injection feature is built on this pattern.

sublimator commented 1 year ago

https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#more-accurate-type-checking-for-parameter-decorators-in-constructors-under-experimentaldecorators

josejustino commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

It worked for me too. Thanks man!

ajubin commented 1 year ago

Hi, thanks for the fix.

One thing I don't understand though is the fact that I already had this line "typescript.tsdk": node_modules/typescript/lib" in my project settings but it was not taken into account.

Isn't it a bug ?

linhvuvan-eh commented 1 year ago

It happens to me even though I don't use JavaScript and TypeScript Nightly extension. Try do disable all extensions that I have, still does not work. My ts version is "typescript": "~4.6.3"

Code that causes the issue

@Inject(forwardRef(() => UsersService))
linhvuvan-eh commented 1 year ago

A coworker of mine fixed it by changing the version of Typescript in vscode.

huyenltnguyen commented 1 year ago

One thing I don't understand though is the fact that I already had this line "typescript.tsdk": node_modules/typescript/lib" in my project settings but it was not taken into account.

Isn't it a bug ?

@ajubin I was caught off-guard too.

But this appears to be an expected behavior, according to the VS Code doc:

The typescript.tsdk workspace setting only tells VS Code that a workspace version of TypeScript exists. To actually start using the workspace version for IntelliSense, you must run the TypeScript: Select TypeScript Version command and select the workspace version.

regalstreak commented 1 year ago

I added "experimentalDecorators": true to my compilerOptions in tsconfig.json. Worked with VSCodes typescript version 5.0.4 image

ghost commented 1 year ago

I tried all the options, but it doesn't work

henzopolicena commented 1 year ago

@GareginAv, it doesn't work for me too. But I was import the @Query from wrong path.

image Now it is correct and works for me.

image

carlossalasamper commented 1 year ago

I'm experiencing the same issue, it's seems like a bug in decorators from 5.0. I'm having this error specifically with the tsyringe decorators

FelipeSinnemann commented 1 year ago

This happened to me. And as you said, it is the JavaScript and TypeScript Nightly extension in vscode, but I didn't disable it to fix this. Just select the typescript version you're using so vscode know what you're using. In your case is 4.9.4.

To make sure you are using typescript@4.9.4:

Open a JavaScript or TypeScript file in VS Code.

In the VS Code command palette, run the TypeScript: Select TypeScript version command. Make sure you have Use Workspace version selected.

image

I love u bro

iamgabrielsoft commented 1 year ago

if the above didn't solve your problem completely then check out this from Stackoverflow, it was really helpful https://stackoverflow.com/questions/38271273/experimental-decorators-warning-in-typescript-compilation

razznblue commented 1 year ago

If you are getting this warning while making a typegoose model, add these three options to your tsconfig.json.

    "strictPropertyInitialization": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
amalashenok commented 1 year ago

@wayn3r, TypeScript: Select TypeScript version works for me, Thank you Bro!

finleywilliamsonV commented 1 year ago

I was still getting the error:

Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.ts(1219)

for an @NgModule() decorator even after TypeScript: Select TypeScript version got rid of the initial error.

What finally worked was setting:

"js/ts.implicitProjectConfig.experimentalDecorators": true

in VSCode's settings.json

raoufmadani commented 12 months ago

Although VS Code is a great editor for TypeScript projects, it needs a kick every now and again. Often, without warning, certain files cause it to freak out and complain. Mostly the fix seems to be to save and close all open files, then open tsconfig.json. After that you should be able to re-open the offending file without error. If it doesn't work, lather, rinse, and repeat.

If your tsconfig.json specifies its source files using the files array, IntelliSense will only function correctly if the file in question is referenced such that VS Code can find it by traversing the input file tree.

Edit: The 'reload window' command (added ages ago now) should solve this problem once and for all.

Hexacker commented 8 months ago

I have faced the same issue today, the fix was just reloading the Typescript server CMD + SHIFT + P then choose TypeScript: Restart TS Server

MonikaR23 commented 6 months ago

If @wayn3r solution didn't solve your problem, you may want to check your tsconfig.json (which should already have "experimentalDecorators": true) and make sure you have the following:

{
  "include": [
    "src/**/*.ts",
  ]
}
ootkin commented 6 months ago

If @wayn3r solution didn't solve your problem, you may want to check your tsconfig.json (which should already have "experimentalDecorators": true) and make sure you have the following:

{
  "include": [
    "src/**/*.ts",
  ]
}

This fixed for me!

nsk1703 commented 5 months ago

Thank you very much!!

WendaoLee commented 4 months ago

I added "experimentalDecorators": true to my compilerOptions in tsconfig.json. Worked with VSCodes typescript version 5.0.4 image

yep,this works for me.The document here:https://www.typescriptlang.org/tsconfig/#experimentalDecorators

salqadri commented 3 months ago

Although VS Code is a great editor for TypeScript projects, it needs a kick every now and again. Often, without warning, certain files cause it to freak out and complain. Mostly the fix seems to be to save and close all open files, then open tsconfig.json. After that you should be able to re-open the offending file without error. If it doesn't work, lather, rinse, and repeat.

If your tsconfig.json specifies its source files using the files array, IntelliSense will only function correctly if the file in question is referenced such that VS Code can find it by traversing the input file tree.

Edit: The 'reload window' command (added ages ago now) should solve this problem once and for all.

I tried all the above in vain; this is what finally worked for me. ty.

tanishq14developer commented 3 months ago

This save my entire day !!!