无法为Power BI自定义可视开发安装d3类型

Mar*_*nce 5 d3.js powerbi typescript-typings

我在安装d3打字机时遇到问题.我按照微软的说明访问了https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/Typings.md,以及Sachin Patney在他的视频中所做的工作:https://www.youtube.com/watch ?v = _2-yMGtEv2w.

运行"npm install typings -g"似乎工作正常.

运行"typings install --save --global dt~d3"或"typings i dt~d3 -G"都会产生此错误:"typings ERR!message尝试编译"d3"作为全局模块,但它看起来像一个外部模块.您需要删除全局选项才能继续."

如果我删除全局选项,它会在我的visual文件夹中使用路径中的"modules"文件夹而不是"globals"文件夹添加打包信息(即,MyVisual | typings | modules | d3而不是MyVisual | typings | globals | D3).Intellisense也不适用于d3.

知道为什么我不能在全球范围内安装d3打字机吗?

Mar*_*nce 7

虽然@ FabioEnne的答案确实解决了我关于全局安装和智能感知的问题,但我仍然遇到了与该问题的最初原因相关的其他问题.但我想我找到了修复......

据Jon Gallant说:

Power BI团队刚刚发布了Custom Visuals SDK的v1.2.有了这个版本,你现在需要自己参考d3 v3.5.5.d3 v4还没有用.我正在与团队合作,共同获得v4 compat和样本,但是现在你只能使用v3.5.5.

(@ FabioEnne的解决方案将v4.4.0添加到我的系统中.)

Jon在他的网站上提供了解决这个问题的方法:http://blog.jongallant.com/2016/11/pbiviz-12-d3-35-reference/.(他收录了一段视频.)

Jon的解决方案的要点是:

安装类型:

npm i -g typings
Run Code Online (Sandbox Code Playgroud)

添加d3 v3.5.5:

npm i d3@3.5.5 --save
Run Code Online (Sandbox Code Playgroud)

添加d3输入:

typings install d3=github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts#6e2f2280ef16ef277049d0ce8583af167d586c59 --global --save
Run Code Online (Sandbox Code Playgroud)

将文件添加到tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES5",
    "sourceMap": true,
    "out": "./.tmp/build/visual.js"
  },
  "files": [
    ".api/v1.3.0/PowerBI-visuals.d.ts",
    "typings/index.d.ts",
    "node_modules/d3/d3.min.js",
    "src/visual.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)