Skip to content

Legacy/Experimental parameter decorators fails with TS1239 when StrictNullChecks is true in Typescript 5.0.2 #53312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mrttrifork opened this issue Mar 17, 2023 · 3 comments Β· Fixed by #53365
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@mrttrifork
Copy link

mrttrifork commented Mar 17, 2023

Bug Report

πŸ”Ž Search Terms

experimentalDecorator, TS1239, parameter decorator

πŸ•— Version & Regression Information

4.8.3 -> 5.0.2

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

I provided the playground link

πŸ™ Actual behavior

i assume @Dependency("test) returns undefined and i set the type to string so i assume that's why it fails now

πŸ™‚ Expected behavior

There should be no error

@notaphplover
Copy link

It seems legacy decorators now requires their second parameter to allow undefined values:

export function Dependency(injectable: ReferenceType<unknown>) {
    return function (target: any, _: string | undefined, parameterIndex: number) {
       ...
    }
}

Consider this example.

Having said that, it would be great to update legacy decorator typings to reflect this change. This is breaking every single decorator that relies on ParameterDecorator in ts5 with strict null checks. Consider this example.

cc @rbuckton

@mrttrifork
Copy link
Author

Thanks a lot i added

export type UpdatedLegacyParameterDecorator = (target: Object, propertyKey: string | undefined, parameterIndex: number) => void;

as a workaround

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 17, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.1.0 milestone Mar 17, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 20, 2023
@rbuckton
Copy link
Contributor

The reported issue is an expected behavior and is mentioned in the breaking changes section of the 5.0 release blog post: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#more-accurate-type-checking-for-parameter-decorators-in-constructors-under-experimentaldecorators

@notaphplover is correct that the typings for the legacy ParameterDecorator type do not reflect this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants