i have installed popular d3
library through npm
.
npm install d3 tsd install d3 -save tsc
in home.ts
file, have imported module:
import * d3 'd3/d3';
this compiles correctly, semantic error:
app/home/components/home.ts(2,21): error ts2307: cannot find module 'd3/d3'.
also, lose of syntax highlighting/type-ahead info in ide.
the original d3.d.ts
file provided tsd
declares module so:
declare module 'd3' { export = d3; }
if change module 'd3/d3'
, works fine:
declare module 'd3/d3' { export = d3; }
so, i'm having hard time getting both of need:
import * d3 'd3';
gives me type definitions expect, looks module in node_modules/d3.js
incorrect.
import * d3 'd3/d3';
finds correct module because path right, lose type definitions because module declaration doesn't match.
how can these 2 things match can import module without losing type definitions?
fyi: using typescript 1.7.5, , moduleresolution
set node
.
you need tell loader things. in systemjs.config.js
, add following mapping in map
object:
var map= { ... ... 'd3': 'node_modules/d3' };
the d3.js
file indeed located in node_modules/d3
, above mapping let loader find file. now, can import in components as:
import * d3 'd3';
Comments
Post a Comment