microsoft / microsoft/TypeScript
Certain conditional types allow unsound assignments
オープン
まだ誰も着手していません。
Bug
Cursed?
Domain: Conditional Types
Help Wanted
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
"conditional type" generic assignment
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types
⏯ Playground Link
💻 Code
type Box<T> = { value: T }
type UnboxInner<T> = T extends Box<infer R> ? UnboxInner<R> : { unboxed: T }
type Unbox<T> = UnboxInner<T>['unboxed']
declare function unbox<T>(x: T): Unbox<T>
function example<T>(x: T) {
let a = unbox(x)
a = 'this should be an error'
}
🙁 Actual behavior
In example we can assign arbitrary values to a, even though it's typed as Unbox<T>.
🙂 Expected behavior
Attempting to assign invalid values to a (just about anything, since its type depends on a type parameter) should cause a type error.
Additional information about the issue
These issues may possibly be related:
- #52021
- #35533
cc @webstrand
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の TypeScript Playground の再現から始め、関連する issue #52021 および #35533 と動作を比較してください。TypeScript コンパイラーにおける conditional type のジェネリック代入チェックを追跡します。示されている代入が拒否され、その動作をカバーする回帰テストがある状態を完了とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100