microsoft / microsoft/TypeScript
Always verify import path
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
In many projects is necessary work with files which isn't a TS/JS file. Some common ones are png, jpg, svg, but when importing this files we get Cannot find module or its corresponding type declarations. error.
Searching how to fix that, we come across many discussions suggesting using the global module declaration, such as:
declare module '*.svg' {
const content: string
export default content
}
Links
- Importing images in TypeScript React - “Cannot find module”
- Webpack & Typescript image import
- Typescript image import
- TypeScript "Cannot find module './myFile..." for .scss, .less, images files, wasm...
- Importing SVG files as React Components in TypeScript
This approach fix the lint error, but disable TS intellisense.
Example
Folder structure
app
|
├ img
| └─ top-view.svg
|
└─index.ts
index.ts

No errors, but the correct path is ../img/top-view.svg
Here is the related issue #40333
Suggestion
Compiler could still returning missing type declarations for not TS/JS files. But always check if import path results in a file and return an error if not (even if file is not an TS/JS).
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 Lesen des zugehörigen Issue #40333 und der Beispiele in diesem Bericht. Untersuche anschließend das Verhalten der Importpfadauflösung von TypeScript für Dateien, die keine TS/JS-Dateien sind. Als abgeschlossen gilt die Arbeit, wenn das vorgeschlagene Verhalten der Diagnose für fehlende Dateien definiert und implementiert ist, ohne die Unterstützung für deklarierte Nicht-Code-Module zu verlieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100