microsoft / microsoft/TypeScript
Declaration emit incorrectly prints uninstantiated generic type
@weswigham がすでに取り組んでいます。
2021年6月24日 から。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
I have a type with an unused generic type parameter.*
This type annotates an optional parameter property in the constructor of a class.
Starting with Version 4.2.X of TypeScript, this class is incorrectly transpiled, so that TS code using the transpiled sources (.d.ts) does not transpile anymore.
The error was:
error TS2304: Cannot find name 'T'
No wonder it cannot be found, it was not in the original code (please see the minimal example below).
During my investigation I found that this issue occurs, when these prerequisites are met:
- The given type has an unused generic parameter.
- The given type represents a union type.
- You have a class with a constructor argument using the given type.
- The constructor argument is a parameter property.
- The constructor argument is optional.
This list might not be complete or exact.
* (Tried something. Didn't work. Postponed it, but left the parameter for later use.)
🔎 Search Terms
generics, transpilation, missing parameter
🕗 Version & Regression Information
- This changed between versions 4.1.X and 4.2.X
⏯ Playground Link
Playground link with relevant code
💻 Code
Before transpilation:
type BrokenType<T> = 'a' | 'b';
class MyClass {
constructor(readonly arg?: BrokenType<any>) {}
}
After transpilation
declare type BrokenType<T> = 'a' | 'b';
declare class MyClass {
readonly arg?: BrokenType<T> | undefined;
constructor(arg?: BrokenType<T> | undefined); // <----- T should be any
}
🙁 Actual behavior
The code is transpiled to contain the generic parameter name, instead of the actual type that was passed as argument.
🙂 Expected behavior
I would expect the result to contain the original type as specified in the original code. The generic parameter is not known when consuming the type. This worked before version 4.2.X.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。