microsoft / microsoft/TypeScript

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

未关闭
#61,501 1 条评论 2 个 reaction 已指派 1 人 在 GitHub 查看

@weswigham 已经在做这个了。

开始于 2025年3月28日。

Needs Investigation
主要语言
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

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。