Typescript 'is not a module error

I have an Angular2 project where I need to import a javascript file for use in my typescript.

I have a javascript file in app / js / d3gantt.js that contains a single function gantt = function().

gantt = function() {
    //Does lots of stuff
    return gantt;
};

Then I have a d3gannt.d.ts definition file in the same folder that looks like this:

declare module 'd3Gantt' {
    export module d3Gantt {
        export function gantt(): any;
    }
}

And then I refer to it in my component as import * as d3Gantt from '../app/js/d3gantt';

However, I get an error File 'c:/Projects/RepackLog/RepackLog/RepackLog/app/js/d3gantt.d.ts' is not a module

Am I missing something that is necessary for this to select my files correctly?

Thank,

+4
source share
2 answers

, @FabioAntunes gantt d3gantt.js .

export gantt = function() {
    //Does lots of stuff
    return gantt;
};

. . (Typescript es6 " " .

+1

, :

declare module 'd3Gantt' {
  export function gantt(): any;    
}

: import * from 'path to your module file' import * as d3 from 'path to your module file'

+1

Source: https://habr.com/ru/post/1659171/


All Articles