microsoft / microsoft/TypeScript
checkJs: x.js should use x.d.ts for type inference
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Suggestion
🔍 Search Terms
checkjs, declaration files
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
If a declaration file with the same name than a JavaScript file is available (in the same location), then the declaration file should be used to check the js file.
📃 Motivating Example
Assume that "checkJs" and "strict" options are enabled.
Given the following files:
// @filename a.d.ts
export function f(n: number): number;
// @filename a.js
function f(a) {
// Parameter 'a' implicitly has an 'any' type
return a + 1
}
the type of f should be inferred and should thus type-check. TSC does not currently use a.d.ts to infer types of a.js.
Note that importing f in another js file, already infer f's type
// @filename b.js
import { f } from "./a.js"
// type of f is inferred
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
Inizia con il riproduttore di checkJs e strict usando a.d.ts, a.js e b.js, quindi esegui il checker di TypeScript su di esso per confermare la diagnostica attuale. Traccia come viene risolto il file di dichiarazione per l’f importato e confrontalo con il controllo diretto di a.js. È completato quando la dichiarazione con lo stesso nome viene usata per il controllo dei tipi di a.js senza modificare il JavaScript emesso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100