microsoft / microsoft/TypeScript

Assignment of argument to argument loses deduced typing

オープン
#26,397 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: check: Control Flow
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

Could be a duplicate but difficult to construct an issue search to discern.

Problem shows with typescript@latest version 3.0.1.

Given nature of problem suspect that it would not have been fixed in typescript@next. Apologies for not testing.

type inference error argument

Code

// A *self-contained* demonstration of the problem follows...
// Just paste this code into your favorite TypeScript IDE
function foobar_good(arg: unknown): void | number {

  if (typeof arg != 'number') {
    return
  }

  return arg;
}

function foobar_bad(arg: unknown): void | number {

  if (typeof arg != 'number') {
    return
  }

  arg = arg;

  return arg;
}

[ts] Type 'unknown' is not assignable to type 'number | void'.
Type 'unknown' is not assignable to type 'void'.

Expected behavior:
Should compile.

Actual behavior:
Does not compile.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue にある自己完結型の TypeScript の例から始め、TypeScript 3.0.1 でコンパイルし、foobar_good と foobar_bad を比較します。arg 自身への代入が unknown から number への絞り込みにどのような影響を与えるかを調査します。示されたコードがコンパイルでき、期待される型チェックの動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。