错误出现:
src\globals.d.ts
声明全局 interfaceimport { ColorRepresentation } from "three"; interface Scene { background?: ColorRepresentation; models?: any; needAxesHelper?: boolean; }
glEquM.ts
项目中引用export class glEquM { sceneInfo: Scene }
出现错误提示没有声明
Scene
问题出现原因
*.d.ts
导入import
其它类型会导致全局类型失效
如果在 .d.ts 文件中使用了 import 或者 require 等方式引入了其他模块,那么 ts 就会将其视为一个模块,从而导致文件下的所有类型声明直接失效。
问题解决方法
通过创建全局命名空间的方式,将想要使用的类型声明挂载到全局命名空间上。
src\globals.d.ts
修改代码如下
import { ColorRepresentation } from "three";
declare namespace glEquMType {
interface Scene {
background?: ColorRepresentation;
models?: any;
needAxesHelper?: boolean;
}
}
export = glEquMType
export as namespace glEquMType
glEquM.ts
项目中引用
export class glEquM {
sceneInfo: glEquMType.Scene
}
解决啦~ OVER