microsoft / microsoft/TypeScript
JSDoc @type annotation ignored in chained variable declaration
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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;
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Non sono indicati né un file sorgente né un test. Inizia riproducendo localmente l'esempio JavaScript con TypeScript 3.7.2 o con la build 3.8.0-dev segnalata, quindi traccia la gestione di JSDoc per le dichiarazioni in un'istruzione var concatenata. Il lavoro è concluso quando il compilatore segnala lo stesso errore di tipo per num1 e per num2, con un test di regressione che copra entrambe le forme.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100