microsoft / microsoft/TypeScript
Predicates break arbitrarily when intersected with some types. (Probably when the predicate is generic).
オープン
まだ誰も着手していません。
Bug
Domain: Intersection
Help Wanted
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
predicate intersection
🕗 Version & Regression Information
latest version v5.6.2
⏯ Playground Link
💻 Code
interface TruthyPredicate {
<T>(o: T): o is T & {};
}
interface EmptyInterface {
}
type ConstructorSignagure = {
new (...args: any[]): any;
};
declare const arr: (string | undefined)[];
declare const predicate1: TruthyPredicate;
const filtered1 = arr.filter(predicate1); // works string[]
declare const predicate2: TruthyPredicate & EmptyInterface;
const filtered2 = arr.filter(predicate2); // doesn't work
declare const predicate3: TruthyPredicate & {} /* Empty object type instead of interface */;
const filtered3 = arr.filter(predicate3); // works string[]
declare const predicate4: TruthyPredicate & ConstructorSignagure;
const filtered4 = arr.filter(predicate4); // doesn't work
🙁 Actual behavior
Predicate stops working
🙂 Expected behavior
Predicate works
Additional information about the issue
I tried other scenarios
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
TypeScript Playground の再現例と Code セクションの Array.filter 呼び出しから始め、predicate1 から predicate4 までを比較します。TruthyPredicate と EmptyInterface または ConstructorSignagure を交差させるとなぜ narrowing が失われるのかを調査します。影響を受ける交差型によって、追加で説明されているジェネリックのケースを壊すことなく、フィルタリングされた配列が期待どおりに絞り込まれれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100