打字稿中未定义的d3.scale [英] undefined d3.scale in Typescript

查看:87
本文介绍了打字稿中未定义的d3.scale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Typescript(2周),我的项目包装d3.js框架。
我遇到了使用d3.d.ts,命名空间,导出模块,导入的问题。



我的问题:当我尝试使用d3.scale.linear(),我在浏览器控制台中出现错误:

  TypeError:d3.scale is undefined 

代码:

  ///< reference path =../ typings / d3.d.ts> ;; 
use strict;
var linear = d3.scale.linear();
console.log(linear resolv!)

我的编译器选项编译过程没有错误,但可能很有趣):

  {
files:[
src / twod3 / component.ts,
src / twod3 / component / basic.ts,
src / twod3 /

编译器选项:{
noImplicitAny:true,
target:es2015,
module:commonjs,
sourceMap:true
}
}
/ pre>

我尝试不同的导入策略没有成功。



d3.d.ts

 声明命名空间d3 {
...
导出模块缩放{
...
export function linear():Linear< number,number> ;;
...
}
}

注意d3.js的版本

>
在版本4.2.1 d3.scale.linear();给出以下错误。
TypeError:d3.scale.linear()scale未定义



我使用d3.scaleLinear ;


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();

这篇关于打字稿中未定义的d3.scale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆