Skip to content
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

[isolatedDeclarations] Optional parameter properties are unnecessarily disallowed in isolatedDeclarations mode #61501

Open
blickly opened this issue Mar 28, 2025 · 0 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@blickly
Copy link
Contributor

blickly commented Mar 28, 2025

🔎 Search Terms

optional parameter properties, isolated declarations, TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations

🕗 Version & Regression Information

  • This was present since the introduction of isolatedDeclarations in TS5.5

⏯ Playground Link

https://www.typescriptlang.org/play/?downlevelIteration=true&importHelpers=true&target=99&module=1&isolatedDeclarations=true&ts=5.8.2&ssl=6&ssc=2&pln=1&pc=1#code/C4TwDgpgBAsghiARhAqgOwCYQGYEs0QZQC8UaArgLbIBOUAPlOZjvoQNwBQokUAchABuEGuix4CRUhWoiunCAA8wAexrAoAYwA2cAM56oAMRUqoAb05RrWlWj3Aa5TcDUAKGhDgY72kFEUAfgAuWARkMVZJABooT29ffxAQ-iERSIlCAEoLAF9OXKA

💻 Code

type MaybeUndefined = number | undefined;
type NeverUndefined = number;

export class Foo {
    constructor(readonly x?: MaybeUndefined, readonly y?: NeverUndefined) {}
}

🙁 Actual behavior

Gives an error:

Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.

🙂 Expected behavior

It seems like this could be safely supported by just always emitting the class fields with a type of |undefined whether that was redundant or not, something like:

export declare class Foo {
    readonly x?: MaybeUndefined | undefined;
    readonly y?: NeverUndefined | undefined;
    constructor(x?: MaybeUndefined, y?: NeverUndefined);
}

Additional information about the issue

The workaround of explicitly adding |undefined to the parameter property types is not too onerous, but still seems like an unnecessary restriction for isolatedDeclarations mode.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants