typescript 打字稿中未定义的 d3.scale

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38218891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:37:41  来源:igfitidea点击:

undefined d3.scale in Typescript

d3.jstypescript

提问by Rémy Letient

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.

我是 Typescript 的新手(2 周),我正在从事包装 d3.js 框架的项目。我在使用“d3.d.ts”、命名空间、导出模块、导入时遇到问题。

My problem : When I try to use the d3.scale.linear(), I have the error in my browser console :

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

    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

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.

没看懂问题,谢谢大家的帮助。

回答by jcoggins

Be careful of the version for d3.jsIn version 4.2.1 d3.scale.linear(); gives the following error. TypeError: d3.scale.linear() scale is undefined

注意 d3.js版本在 4.2.1 版本中 d3.scale.linear(); 给出以下错误。类型错误:d3.scale.linear() 比例未定义

I fixed this error in version 4.2.1 by using d3.scaleLinear();

我在 4.2.1 版本中使用 d3.scaleLinear() 修复了这个错误;

回答by sg28

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 u update your bower . Or match the in built methods for your current version .

我遇到了类似的问题。我必须匹配支持 d3 内置方法的 D3 版本。要么匹配 D3.js 的版本,确保你更新你的凉亭。或者匹配您当前版本的内置方法。

My supported version for d3.scale.ordinal is '3.5.17',previously i was at the latest version.

我支持的 d3.scale.ordinal 版本是“3.5.17”,以前我是最新版本。