使用公共变量,并使用打字稿,当外部库接口 [英] Using public variables and interfaces in external libraries when using Typescript

查看:180
本文介绍了使用公共变量,并使用打字稿,当外部库接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的打字稿及正在开发一个角2.0 /打字稿应用。我已提供D3作为一个打字,我想用公共的方法从D3以及接口。

为了可以D3我加入以下code:

声明VAR D3

我需要使用以下接口:

私人_axises:D3.Selection

和下面的公共方法。

this._axises = d3.select(...)

我如何使这两个D3和D3可使用无打字稿transpiler抛出任何错误?

感谢


解决方案

  

我如何使这两个D3和D3可使用无打字稿transpiler抛出任何错误?


您似乎想使用的社区的书面D3 defintions。在这种情况下,你不应该添加的的自己,即没有声明VAR D3 在code的任何地方。这应该有 d3.d.ts 可在这里:的 https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3

更多

您可以用它分型安装分型安装D3 --ambient --save 。此外,如果你正在使用一个模块系统中使用进口*为D3例如D3在 alm.tools 我有<一个href=\"https://github.com/alm-tools/alm/blob/894a6f095ecc84c8e32adf79c1bb7d595eba877d/src/app/tabs/dependencyView.tsx#L8\" rel=\"nofollow\">https://github.com/alm-tools/alm/blob/894a6f095ecc84c8e32adf79c1bb7d595eba877d/src/app/tabs/dependencyView.tsx#L8

I am fairly new to Typescript and am developing an Angular 2.0/Typescript application. I have made d3 available as a typing and I would like to use public methods from D3 as well as interfaces.

To make d3 available I have added the following code:

declare var d3

I need to use the following interface:

private _axises: D3.Selection

and the following public method.

this._axises = d3.select(...)

How do I make both "d3" and "D3" available for usage without the Typescript transpiler throwing any errors?

Thanks

解决方案

How do I make both "d3" and "D3" available for usage without the Typescript transpiler throwing any errors?

You seem to want to use community written d3 defintions. In that case you should not add your own i.e. don't have declare var d3 anywhere in your code. This should come with d3.d.ts available here : https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3

More

You can install it using typings typings install d3 --ambient --save. Also if you are using a module system use import * as d3 from "d3" e.g. in alm.tools I have https://github.com/alm-tools/alm/blob/894a6f095ecc84c8e32adf79c1bb7d595eba877d/src/app/tabs/dependencyView.tsx#L8

这篇关于使用公共变量,并使用打字稿,当外部库接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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