microsoft / microsoft/TypeScript
Object spread works for unconstrained generic
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.8.3
Search Terms:
generic
spread
unrestrained
unrestricted
Expected behavior:
The spread function should not compile because T is not constrained to a type that can be spread.
Actual behavior:
It compiles.
Related Issues:
https://github.com/microsoft/TypeScript/issues/30129
https://github.com/microsoft/TypeScript/pull/13288
Code
function spread<T>(t: T) {
// This should not compile
return { ...t };
}
// The type of `result` is `number` even though the value of `result` is `{}`
const result = spread(5);
Output
"use strict";
function spread(t) {
// This should not compile
return Object.assign({}, t);
}
// Result is still a number when in reality it's {}
const result = spread(5);
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Playground リンクの動作を、TypeScript 3.8.3 と記載されたコンパイラーオプションを使って再現します。関連する issue と pull request を読み、unconstrained generic に対する object spread をコンパイラーがどのように処理しているかを追跡します。サンプルが期待どおりに拒否され、結果の型が誤って引数の型のままにならなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100