microsoft / microsoft/TypeScript
[isolatedDeclarations] Optional parameter properties are unnecessarily disallowed in isolatedDeclarations mode
@weswigham 已经在做这个了。
开始于 2025年3月28日。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。