microsoft / microsoft/TypeScript

TS with .js files and JSDoc: type is found, displayed and used - despite "TS2304: Cannot find name XYZ"

Aperta
#31,131 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

checkJs Domain: JSDoc Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

TS 3.4.5, Webstorm 2019.1.1, node v11.14.0, Linux

Project: .ts files in src/, transpiled using Babel to lib/, but files under test/ are .js files

tsconfig.json has allowJs and checkJs set to true in order to check the .js files under test/ — which (CommonJS) require(...) transpiled .js files from lib/ (there also are .d.ts and .d.ts.map files for all files).

Every single TS type declared in src/ has an accompanying JSDoc @typedef (don't know if that is important or if TS does not even use it since there is the original TS type too).

The problem I see is a weird one, because what Typescript says and what it actually does is completely opposite!

In the IDE I see every single type declared in src/ files as read, and on mouseover I get TS2304 Cannot find name "XYZ".:

Unbenannt-1

However, and this is the weird part (1 of 2): It all works!

Showing the type (in WebStorm, CTRL plus mouse-hover over a symbol, shows the correct information. Even on those red types, I get the type name and the file name of where it is declared. Variables show the correct autocompletion suggestions and type information, jumping to the type definition (the TS one) works too.

The other weird part (2 of 2) is that when I follow the suggestions to change e.g.

 * @param {SHA256Hash} hash

to

 * @param {import('../lib/core-types.js').SHA256Hash} hash

the symbols are no longer red — but now nothing works. No more type information or anything. (Tried different import paths, also directly to the src/ files and without extension, for example.)

This is the reason why I file this as a bug. It actually works, so it is not a feature request.

So all it needs is for TS to stop showing the "cannot find name" errors, I don't need a change in behavior, since it does find the names just fine.


PS: I realize this is probably deeper, the plugin does not specifically remove the comments, I think it is the path.remove() command from the underlying AST. That doesn't make it any better or even right though. Others had similar issues in the past.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalle impostazioni tsconfig.json segnalate, in particolare allowJs e checkJs, e riproduci la diagnostica nei file JavaScript di test/ che richiedono file transpilati da lib/. Confronta i riferimenti JSDoc come @param {SHA256Hash} con la forma import(...) e analizza il comportamento correlato di issue #17606. Il lavoro è completato quando i nomi di tipo JSDoc validi non producono più TS2304, preservando le informazioni sul tipo e la navigazione riportate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
babel, javascript, nodejs, 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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.