microsoft / microsoft/TypeScript
Cannot Load Custom Definition File in Repository
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 2.8.1
Search Terms: Definition File, Ambient type
Detail
I am importing a JavaScript library that doesn't have any definition file. I want to create a custom definition file that I place in my repository. I want TypeScript to read this definition file.
I have tried many combination of tsconfig.json (typeRoot, include, path, baseUrl, etc.) Without being successful. I also moved the definition folder under src, and renamed the definition file to index.d.ts (inside a folder with the name of the library) without any success.
Code
Small complete repro here: https://github.com/MrDesjardins/importdefinitionfiles
// main.ts:
import MessageFormat from "messageformat"; // Doesn't have type
// messageformat.d.ts:
declare module messageformat {
export type Msg = (params: {}) => string;
export interface MessageFormat {
new(message: string): any;
compile: (messageSource: string) => Msg;
}
}
Expected behavior: TypeScript to find the definition file and to use it without having a compilation error.
Actual behavior: Error message
Could not find a declaration file for module 'messageformat'. '/Users/pdesjardins/code/perso/importdefinitionfiles/node_modules/messageformat/lib/messageformat.js' implicitly has an 'any' type.
Try `npm install @types/messageformat` if it exists or add a new declaration (.d.ts) file containing `declare module 'messageformat';`
1 import MessageFormat from "messageformat";
Playground Link: https://github.com/MrDesjardins/importdefinitionfiles
Related Issues:
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 damit, das verlinkte importdefinitionfiles-Beispiel mit der gemeldeten TypeScript-Version zu reproduzieren, und vergleiche anschließend das Verhalten mit typescript@next. Lies main.ts, messageformat.d.ts und die referenzierten Einstellungen in tsconfig.json, während du nachverfolgst, warum die lokale Deklaration nicht gefunden wird. Als erledigt gilt die Aufgabe, wenn die benutzerdefinierte Deklaration erkannt wird und der Import ohne den Fehler wegen der fehlenden Deklaration kompiliert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100