-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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 => OKExpected 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;Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript