2017-11-26 1 views
0

Hier ist die Wildcard-Moduldefinition:Wildcard Modultyp für den Import von Text nicht überprüft

declare module 'text!*' { 
    const content: string; 
    export default content; 
} 

Und der Import:

import * as html from 'text!./myHtml.html'; 

Und der Compiler-Fehler:

error TS2345: Argument of type 'typeof 'text!*'' is not assignable to parameter of type 'string | ((this: HTMLElement, index: number, oldhtml: string) => string)'.

Ich bin erwarten Sie wirklich html, um Typ string zu haben.

Antwort

1

I'm really expect html to have type string.

Dann ändern Sie den Export zu einer Zeichenfolge. Ich zeige den ungültigen und korrekten Code unten

Ungültige

declare module 'text!*' { 
    const content: string; 
    export default content; 
} 

Correct

declare module 'text!*' { 
    const content: string; 
    export = content; 
} 
Verwandte Themen