microsoft / microsoft/TypeScript
[isolatedDeclarations] Optional parameter properties are unnecessarily disallowed in isolatedDeclarations mode
@weswigham đang làm issue này rồi.
Từ ngày 28/3/2025.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
🔎 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.