microsoft / microsoft/TypeScript
checkJs: x.js should use x.d.ts for type inference
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem checkJs- und strict-Reproducer unter Verwendung von a.d.ts, a.js und b.js, und führe dann den TypeScript-Checker darauf aus, um die aktuelle Diagnose zu bestätigen. Verfolge, wie die Deklarationsdatei für das importierte f aufgelöst wird, und vergleiche das mit der direkten Prüfung von a.js. Erledigt ist es, wenn die gleichnamige Deklaration für die Typprüfung von a.js verwendet wird, ohne das erzeugte JavaScript zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100