microsoft / microsoft/TypeScript
Declaration emit inlines types incorrectly
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
declaration emit inline
🕗 Version & Regression Information
I was unable to test this prior to 4.4 since React types are no longer compatible with that version.
⏯ Playground Link
No response
💻 Code
import * as React from "react";
export class Component extends React.Component<{ children: React.ReactNode }> {
render() {
if (Math.random()) {
return <div>{this.props.children}</div>;
} else {
return this.props.children;
}
}
}
Full repro: https://github.com/eps1lon/ts-module-auto-export/tree/bad-inline
🙁 Actual behavior
Return value from render() is not referencing React.ReactNode but inlines its (incomplete) union members:
import * as React from "react";
export declare class Component extends React.Component<{
children: React.ReactNode;
}> {
render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element;
}
🙂 Expected behavior
Return type references the type alias. Inlining union members is incorrect (we may add or remove members or treat members as internal, local types) generally and here specially not even using all members.
export declare class Component extends React.Component<{
children: React.ReactNode;
}> {
render(): React.ReactNode | import("react/jsx-runtime").JSX.Element;
}
Additional information about the issue
The fact that it inlines the type here is a special case of https://github.com/microsoft/TypeScript/issues/37151. https://github.com/microsoft/TypeScript/issues/37151 is a more general since it's not always clear when inlining is correct or not. I'd be curious to know what would break if TS would not stop inlining in this special case.
But this issue is also broader since the inline is incomplete.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている ts-module-auto-export の bad-inline 再現から始め、Component.render に対する TypeScript の declaration emit の出力を調べてください。出力された戻り値の型を、期待される React.ReactNode の参照と比較し、その後 issue #37151 を使って関連する inlining の動作を理解してください。完了とは、示されているとおり、union が完全に、かつ type alias を通して出力されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100