microsoft / microsoft/TypeScript

JSDoc @type annotation ignored in chained variable declaration

未关闭
#35,544 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定源文件或测试。首先使用 TypeScript 3.7.2 或报告中的 3.8.0-dev 构建在本地复现 JavaScript 示例,然后跟踪链式 var 语句中声明的 JSDoc 处理。完成的标准是:编译器对 num1 报告与对 num2 相同的类型错误,并且有一个覆盖这两种形式的回归测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
32/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。