microsoft / microsoft/TypeScript

Any type is inferred when function input parameter is set to some value

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

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

Bug Domain: check: Type Inference Needs Human Review Needs More Info
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: 3.8.2

Search Terms: any type is inferred

Code

interface ContinuationQueryResult<T> {
    documents: T[];
    continuation?: string;
}

function abc(continuation?: string): Promise<ContinuationQueryResult<string>> {
    return <any>undefined;
}

async function test() {
    // When not explicitly set to undefined type is inferred correctly.
    let continuation: string | undefined = undefined;

    do {
        const summaries = await abc(continuation);

        continuation = summaries.continuation;
    } while (continuation)
}

Expected behavior:
Type of summaries variable should be ContinuationQueryResult<string>.

Actual behavior:
summaries variable is inferred as any.

Playground Link: https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgMIHtygK5zMTARW2gE8AlCAZ2wBswAeAFQD5kBvAWAChk-kAJugTYAthHBUAXMiYBtALoBuHv2QJM+ELnyYA-DKpgooAOYruAXx48Y2EAl0hkcAEYIAFBqza8BEAbIRiYgpgCUMgAKUOiiwFQQDBg+Ov7EZJQ09AzBZixsXLz8UBBg2FDODHAgpCz2AhAwoBACFtbcPHBUpA7Idg5OyJBGHmEcqvwA9JPIAOoAFhLIIOhgyBAAHgAOtMAIwGC0pEGlQ+jI9Y3NAkOkWyjxyKAw0CU3GlAljkcAdBN8tFO3i0qUwhmMZmQAB8LiAGk0QC1kABeWHw64Wf6Cc6FNRqbxGIJiURwEzUFEuADucAOLncXk0OD8mDCmKKePUjN8g1RNFEJLJVB+wKZTgsaksyEp82AgOQDJSzJAYR4liAA

Related Issues:

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground の再現コードとテスト関数から始め、continuation を undefined で初期化した場合と別の値で初期化した場合の推論を比較してください。オプション引数の型チェック経路を追跡し、回帰テストを追加してください。summaries が any ではなく ContinuationQueryResult として推論されれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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