【发布时间】:2013-11-05 11:59:09
【问题描述】:
我正在使用 TypeScript develop 分支编译 three.d.ts(可从 here 获得)。我收到以下错误:
Types of static property 'Utils' of class 'THREE.Shape' and class 'THREE.Path'
are incompatible
问题是
-
Shape定义了一个静态的Utils类 -
Shape间接继承自Curve -
Curve还定义了一个静态Utils类,其签名与Shape.Utils无关
根据语言规范格式不正确。总结一下,three.d.ts 包含类似以下代码:
declare class A {
static Utils: {
f (): any;
}
}
declare class B extends A {
static Utils: {
// incompatible with A.Utils, without f(): any
g (): any;
}
}
暂且不提为什么静态成员的类型必须与继承的同名静态成员的类型兼容的问题——这在其他几种 OO 语言中并非如此,但似乎确实如此在 TypeScript 中 - 我想知道如何修复 three.d.ts 以便我可以编译它。
我目前的解决方法是将Curve.Utils 的签名复制并粘贴到Shape.Utils 中,以便后者在结构上扩展前者。但是,在.d.ts 文件中捕获底层three.js 文件(here)的签名的“正确”方法是什么?这是继承使用不当的情况吗?
【问题讨论】:
-
澄清:这在 TypeScript 0.9.1-1 下编译,但不在“开发”分支下。
标签: static three.js typescript