microsoft / microsoft/TypeScript
Imports in .d.ts files break wildcard modules declarations
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
TypeScript Version: 3.1.3
Search Terms:
import d.ts wildcard module
Code
main.ts
/// <reference path="./typings.d.ts" />
import template from './template.html';
typings.d.ts
import * as _angular from 'angular';
declare module '*.html' {
const content : string;
export default content;
}
{
"name": "ts-bug",
"version": "1.0.0",
"dependencies": {
"angular": "^1.7.5"
}
}
Compile with:
tsc main.ts
Expected behavior:
Compiled without errors.
Actual behavior:
Compiled with error
main.ts:3:22 - error TS2307: Cannot find module './template.html'.
3 import template from './template.html';
~~~~~~~~~~~~~~~~~
Removing import * as _angular from 'angular'; fixes the issue.
Side Note 1
Regular module declarations work regardless of imports being present.
Side Note 2
import * as _angular from 'angular'; is needed to later do:
declare global {
const angular : typeof _angular;
}
to workaround https://github.com/Microsoft/TypeScript/issues/10178
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
Reproduziere den Bericht mit main.ts und typings.d.ts unter Verwendung von tsc main.ts. Behalte dabei den Import aus angular und die Wildcard-Moduldeklaration für *.html bei. Verfolge, warum der Import in typings.d.ts verhindert, dass ./template.html aufgelöst wird. Erledigt ist die Aufgabe, wenn das Beispiel ohne TS2307 kompiliert und dabei der Import und die Wildcard-Deklaration erhalten bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100