microsoft / microsoft/TypeScript

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

オープン
#61,501 コメント 1 件 リアクション 2 件 担当者 1 名 GitHub で見る

@weswigham がすでに取り組んでいます。

2025年3月28日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。