microsoft / microsoft/TypeScript
[isolatedDeclarations] Optional parameter properties are unnecessarily disallowed in isolatedDeclarations mode
@weswigham y travaille déjà.
Depuis le 28/3/2025.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
🔎 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
💻 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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.