microsoft / microsoft/TypeScript
Suggestion: short-circuit type inference for ternary operators when both branches have the same type
オープン
まだ誰も着手していません。
Domain: Performance
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
From https://github.com/squidfunk/typescript-issue-38339-repro (courtesy of @squidfunk)
TypeScript Version: 3.9.1-rc
Search Terms:
Subtype reduction, ternary
Code
import { JSX } from "preact"
type IntrinsicElements = JSX.IntrinsicElements[keyof JSX.IntrinsicElements]
export type IntrinsicElements2<
T = IntrinsicElements
> = {
[K in keyof T]: K extends "accept"
? T[K] | [string]
: T[K]
}
export type IntrinsicElements3<
T = IntrinsicElements2
> = {
[K in keyof T]: K extends "class"
? T[K] | [boolean]
: T[K]
}
export type IntrinsicElements4<
T = IntrinsicElements3
> = {
[K in keyof T]: K extends "id"
? T[K] | [number]
: T[K]
}
export function foo(): IntrinsicElements4 | undefined {
let t: IntrinsicElements4 | undefined
// this takes 2 seconds to check
return t
// this takes 10 seconds to check
// return true ? t : t
}
Expected behavior: return t and return true ? t : t check in a comparable amount of time
Actual behavior: the ternary is much slower
Related Issues: #38339
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた再現例と Playground の例から始め、提供された TypeScript コード内の単独の return と三項演算子による return を比較します。三項演算子の型チェック処理と関連する issue #38339 を調査します。両方の形式が期待される型を変更せず、同程度の時間でチェックされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100