microsoft / microsoft/TypeScript
Unsound calls allowed on a function coming from a deferred indexed access when intersection is involved
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
deferred index access unsound call union intersection
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
type A = {
type: "A";
value: string;
};
type B = {
type: "B";
value: number;
};
type Message = A | B;
export function handle<M extends Message>(callbacks: {
[K in M["type"]]: (msg: (M & { type: K })["value"]) => unknown;
}) {
window.addEventListener("message", (event) => {
const msg = event.data as M;
// should be an error because it's too permissive
callbacks[msg.type as keyof typeof callbacks](msg.value);
// one or the other must be wrong here
callbacks[msg.type as keyof typeof callbacks]("");
callbacks[msg.type as keyof typeof callbacks](100);
});
}
🙁 Actual behavior
There is no error even though it should be based on Ander's comment here. Note that the comment is about a different variant of this signature, one using Extract. Both the Extract and intersection variants are essentially the same though - one errors today and one doesn't.
🙂 Expected behavior
I would expect to get an error here, just like in the Extract-based variant (TS playground)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、intersection ベースのシグネチャと Extract ベースのバリアントを比較します。一方のバージョンで "" と 100 を受け取る 2 つの呼び出しがエラーにならない理由を特定し、その後リグレッションテストを追加して、安全でない呼び出しが拒否されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100