Typescript index.d.ts npm 包中深层嵌套函数的声明
Typescript index.d.ts declaration for deeply nested function in an npm package
很遗憾,@types/rickshaw
好像是空的,只好自己制作声明文件了。这是我现在的:
declare module 'rickshaw' {
export class Graph {
constructor(obj: any);
render: any;
}
}
这让我可以使用方法 render
并完美地创建一个新实例。但现在我想从人力车中声明一个深度嵌套的方法。我当前的声明不允许我使用此错误:
Rickshaw.Graph.Axis.Time({graph: newGraph})
(25,41): Property 'Axis' does not exist on type 'typeof Graph'.
我查看了该方法的源代码,它看起来像这样
Rickshaw.namespace('Rickshaw.Graph.Axis.Time');
Rickshaw.Graph.Axis.Time = function(args) {
//...
}
如何申报Rickshaw.Graph.Axis.Time
?
编辑:这是我的新声明文件。我现在 运行
'new' expression, whose target lacks a constructor signature implicitly has an any type
interface TimeArgs {
graph: typeof Graph;
ticksTreatment: string;
}
interface AxisInterface {
Time: (args: TimeArgs) => void;
}
export class Graph {
constructor(obj: any);
render: any;
static Axis: AxisInterface;
}
我试图通过声明 tyepof Graph
来修复它,因为 Time
中的 graph
参数是 new Rickshaw.Graph
对象的一个实例,但我仍然得到错误.
我不熟悉rickshaw
但是你已经添加了Graph
,现在你可以在Graph
里面添加Axis
然后添加Time
里面 Axis
:
declare module 'rickshaw' {
interface TimeArgs {
graph: any;
}
interface AxisInterface {
Time: (args: TimeArgs) => void;
}
export class Graph {
constructor(obj: any);
render: any;
static Axis: AxisInterface;
}
}
并添加您认为合适的任何其他 types/interfaces。
很遗憾,@types/rickshaw
好像是空的,只好自己制作声明文件了。这是我现在的:
declare module 'rickshaw' {
export class Graph {
constructor(obj: any);
render: any;
}
}
这让我可以使用方法 render
并完美地创建一个新实例。但现在我想从人力车中声明一个深度嵌套的方法。我当前的声明不允许我使用此错误:
Rickshaw.Graph.Axis.Time({graph: newGraph})
(25,41): Property 'Axis' does not exist on type 'typeof Graph'.
我查看了该方法的源代码,它看起来像这样
Rickshaw.namespace('Rickshaw.Graph.Axis.Time');
Rickshaw.Graph.Axis.Time = function(args) {
//...
}
如何申报Rickshaw.Graph.Axis.Time
?
编辑:这是我的新声明文件。我现在 运行
'new' expression, whose target lacks a constructor signature implicitly has an any type
interface TimeArgs {
graph: typeof Graph;
ticksTreatment: string;
}
interface AxisInterface {
Time: (args: TimeArgs) => void;
}
export class Graph {
constructor(obj: any);
render: any;
static Axis: AxisInterface;
}
我试图通过声明 tyepof Graph
来修复它,因为 Time
中的 graph
参数是 new Rickshaw.Graph
对象的一个实例,但我仍然得到错误.
我不熟悉rickshaw
但是你已经添加了Graph
,现在你可以在Graph
里面添加Axis
然后添加Time
里面 Axis
:
declare module 'rickshaw' {
interface TimeArgs {
graph: any;
}
interface AxisInterface {
Time: (args: TimeArgs) => void;
}
export class Graph {
constructor(obj: any);
render: any;
static Axis: AxisInterface;
}
}
并添加您认为合适的任何其他 types/interfaces。