microsoft / microsoft/TypeScript

JSDoc @type annotation ignored in chained variable declaration

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

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

I'm not sure whether this is a bug or a feature request:

TypeScript Version: Version 3.8.0-dev.20191206
also confirmed in 3.7.2

Search Terms: type ignored

Code

var 
/** @type {string} */
str1,
/** @type {number} */
num1;

/** @type {string} */
var str2;
/** @type {number} */
var num2;



str1 = "Hello";
num1 = "World"; // TSC does not complain => not OK

str2 = "Hello";
num2 = "World"; // TSC complains => OK

Expected behavior:

test.js:15:1 - error TS2322: Type '"World"' is not assignable to type 'number'.

15 num1 = "World";

test.js:18:1 - error TS2322: Type '"World"' is not assignable to type 'number'.

18 num2 = "World";

Actual behavior:

test.js:18:1 - error TS2322: Type '"World"' is not assignable to type 'number'.

18 num2 = "World";

Playground Link: Unable to reproduce any type related warning in JS PlayGround, please test locally

Related Issues: #22434, #13371 (somewhat related)

The official JSDoc documentation says nothing about mixing types within one var statement, but I guess that if the TS notation works, the behavior for JS might be the same.

var str1: string,
num1: number;

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

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

はじめの一歩

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

調査の方向性

ソースファイルもテストも指定されていません。まず TypeScript 3.7.2 または報告された 3.8.0-dev ビルドを使って JavaScript の例をローカルで再現し、その後、連結された var 文内の宣言に対する JSDoc の処理を追跡してください。完了の条件は、コンパイラーが num2 と同じ型エラーを num1 に対して報告し、両方の形式を対象とする回帰テストがあることです。

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

評価

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

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

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