microsoft / microsoft/TypeScript

checkJs: x.js should use x.d.ts for type inference

Aperta
#44,946 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
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

  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 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.