microsoft / microsoft/TypeScript
Common property check isn't performed when the target has any index signature
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
common property check weak type index signature
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Delay<TDelay extends string> = TDelay | number;
interface MachineConfig<TDelay extends string> {
types?: unknown;
after?: {
[K in Delay<TDelay>]?: number;
};
}
declare function test<
TDelay extends string,
TConfig extends MachineConfig<TDelay>,
>(config: { types: { delays: TDelay } } & TConfig): void;
test({
types: {} as {
delays: "one second" | "one minute";
},
after: {
// @ts-expect-error
oops_this_is_unknown_delay: 100,
},
});
function test2<T extends { [x: `id-${number}`]: string }>(a: T) {}
test2({
// @ts-expect-error
random: true,
});
function test3<T extends { [x: symbol]: string }>(a: T) {}
test3({
// @ts-expect-error
random: true,
});
🙁 Actual behavior
No errors are raised here since index signatures turn off the common property check completely.
🙂 Expected behavior
I don't have a good intuition about the common property check so I'm not sure if all of those 3 examples should be treated as bugs/possible improvements. I think though that especially the first one is surprising because I have a list of 2 concrete string properties that are meant to be allowed there and yet the unrelated~ index signature for numbers turns off this check, leading to accidental problems at runtime.
Additional information about the issue
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている TypeScript Playground から始めて、test、test2、test3 にある3つの例を比較してください。mapped、template-literal、symbol の各 index signature に対して common property check がどのように動作するかを追跡してください。3つすべてのケースについて、意図された診断と期待される扱いが確立されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100