microsoft / microsoft/TypeScript
Regression in generic inference with JSX in v5.7+
オープン
まだ誰も着手していません。
Domain: JSX/TSX
Help Wanted
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
tsx generic
🕗 Version & Regression Information
- This changed between versions 5.6.3 and 5.7.3
⏯ Playground Link
💻 Code
import { defineProps as vueDefineProps } from 'vue';
declare const Comp: {
new <__VERTER__TS__T extends string = ''>(): {
$props: defineProps<__VERTER__TS__T>
};
}
(
<Comp name="foo"
onName={e => {
// @ts-expect-error this should never happen
if (e !== 'dd') {
}
}} />
);
; function TemplateBindingFN<T extends string>() {
const Props = vueDefineProps<{
name: T;
onName: (n: T) => void;
}>()
return { defineProps: Props as typeof Props }
};
export type defineProps<T extends string> = ReturnType<typeof TemplateBindingFN<T>>['defineProps']
🙁 Actual behavior
In later version the onName argument does not get the generic information resolved, defaulting to string, earlier versions 5.x infer e as 'foo'
🙂 Expected behavior
e should be implicitly inferred based on the generic passed in name
Additional information about the issue
It seems to be caused by the type mutation of DefineProps
export type DefineProps<T, BKeys extends keyof T> = Readonly<T> & {
readonly [K in BKeys]-?: boolean
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、バージョン 5.6.3 と 5.7.3 の間で推論の挙動を比較し、その後、参照されている Vue DefineProps の型の変更を確認してください。JSX コールバックパラメーターが string ではなく、name を介して渡されたリテラルのジェネリック値として推論され、再現コードが引き続き有効であれば、修正は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100