簡體   English   中英

使用Typescript時在外部庫中使用公共變量和接口

[英]Using public variables and interfaces in external libraries when using Typescript

我是Typescript的新手,正在開發Angular 2.0 / Typescript應用程序。 我已經使d3可以用作輸入,並且我想使用D3的公共方法以及接口。

為了使d3可用,我添加了以下代碼:

declare var d3

我需要使用以下界面:

private _axises: D3.Selection

以及以下公共方法。

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

如何在Typescript編譯器不會引發任何錯誤的情況下使“ d3”和“ D3”同時可用?

謝謝

如何在Typescript編譯器不會引發任何錯誤的情況下使“ d3”和“ D3”同時可用?

您似乎想使用社區編寫的d3定義。 在這種情況下,你不應該添加自己的 ,即沒有declare var d3在你的代碼的任何地方。 這應該帶有d3.d.ts可從此處獲得: https : //github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3

更多

您可以使用typings install d3 --ambient --save來安裝它類型typings install d3 --ambient --save 另外,如果您正在使用模塊系統,請使用import * as d3 from "d3"中的import * as d3 from "d3"例如在alm.tools中,我有https://github.com/alm-tools/alm/blob/894a6f095ecc84c8e32adf79c1bb7d595eba877d/src/app/tabs/dependencyView。 TSX#L8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM