microsoft / microsoft/TypeScript
JSDoc @type annotation ignored in chained variable declaration
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by reproducing the JavaScript example locally with TypeScript 3.7.2 or the reported 3.8.0-dev build, then trace JSDoc handling for declarations in a chained var statement. Done means the compiler reports the same type error for num1 as it does for num2, with a regression test covering both forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100