I'm new with Typescript (2 weeks), and I work on project to wrap the d3.js framework. I'm encountered a problem with the usage of "d3.d.ts", namespace, export module, import.
My problem : When I try to use the d3.scale.linear(), I have the error in my browser console :
TypeError: d3.scale is undefined
The code :
/// <reference path="../typings/d3.d.ts">;
"use strict";
var linear = d3.scale.linear();
console.log("linear resolv !")
My compiler option (I've no error on the compilation process, but perhaps it's interesting) :
{
"files": [
"src/twod3/workspace.ts",
"src/twod3/component/basic.ts",
"src/twod3/component/data.ts",
"src/twod3/component/operation.ts",
"src/main.ts"
],
"compilerOptions": {
"noImplicitAny": true,
"target": "es2015",
"module":"commonjs",
"sourceMap":true
}
}
I try different import strategy without success.
The d3.d.ts
declare namespace d3 {
...
export module scale {
...
export function linear(): Linear<number, number>;
...
}
}
I don't understand the problem, thank you for your help.
Be careful of the version for d3.js In version 4.2.1 d3.scale.linear(); gives the following error. TypeError: d3.scale.linear() scale is undefined
I fixed this error in version 4.2.1 by using d3.scaleLinear();
I had a similar kind of issue. I had to match the D3 version, that supported the in built methods for d3. Either match the version of the D3.js, make sure you update your browser or match the in built methods for your current version.
My supported version for d3.scale.ordinal
is '3.5.17', previously I was at the latest version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With