strictFunctionTypes prevents an assignment not related to functions
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 28/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
test.ts にある提供された例を tsc test.ts --strictFunctionTypes で再現し、2 つの代入結果を比較してください。payload には実装ファイルも回帰テストも記載されていないため、報告されたジェネリックな mapped type の代入について、型チェックの経路を追跡してください。報告された代入の挙動が期待される結果と一致し、厳密な関数パラメーター検査に回帰が生じなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
TypeScript Version: 3.3.0-dev.20181122
Search Terms:
covariance, contravariance, keyof, interface, class, generic
Code
interface IBase {
foo: string;
}
interface IDerived extends IBase {
bar: string;
}
type StringPropertyNames<T> = { [P in keyof T]: T[P] extends string ? P : never }[keyof T]
type StringProperties<T> = Pick<T, StringPropertyNames<T>>
interface Foo<T> {
readonly Bar: StringProperties<T>;
}
let baseProperties: StringProperties<IBase>
let derivedProperties: StringProperties<IDerived>
let baseInterface: Foo<IBase>
let derivedInterface: Foo<IDerived>
baseProperties = derivedProperties // no error
baseInterface = derivedInterface
tsc test.ts --strictFunctionTypes
Expected behavior:
Compiles without errors.
Actual behavior:
test.ts:23:1 - error TS2322: Type 'Foo<IDerived>' is not assignable to type 'Foo<IBase>'.
Property 'bar' is missing in type 'IBase' but required in type 'IDerived'.
23 baseInterface = derivedInterface
~~~~~~~~~~~~~
test.ts:6:5
6 bar: string;
~~~
'bar' is declared here.
Related Issues:
#24190
The documentation says:
Under --strictFunctionTypes function type parameter positions are checked contravariantly instead of bivariantly.
I couldn't find any information saying it should affect anything else.
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 106
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microsoft/TypeScript#64322 · コメント 2 件 · リアクション 1 件 · 担当者 2 名 ·
-
Possible Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/TypeScript#64278 · コメント 1 件 · リアクション 1 件 ·
-
Docs
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
microsoft/TypeScript#64118 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
microsoft/TypeScript#64094 ·
-
Docs
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/TypeScript#63959 · コメント 5 件 ·
microsoft/TypeScript の issue をすべて見る
似ている issue
-
Type/Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
OpenNSW/nsw-srilanka#497 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
kubernetes-sigs/prow#953 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
caddyserver/caddy#8046 ·