【发布时间】:2020-02-04 06:15:31
【问题描述】:
我正在为现有的 JavaScript 应用程序编写一个插件 - Forge Autodesk.Viewing
在第 6 版之后,他们在应用包中包含了 THREE.js。
现在我可以像这样将它与我的插件一起使用:
declare var THREE:any;
但是我丢失了所有类型,所以我通过以下方式安装了three.js:
npm install --save three
我可以使用三个并导入它,但我不需要导入它,因为我已经在我的主应用程序中拥有它。我需要做的是引用类型,所以我尝试做这样的事情:
declare var THREE:THREE;
//Cannot use namespace 'THREE' as a type.
然后我尝试:
/// <reference types='three' /> 工作正常,但是:
const planes:THREE.Plane[] = []; //this line is okey
planes.push(new THREE.Plane()); //but this says
//'THREE' refers to a UMD global,
// but the current file is a module.
// Consider adding an import instead.
Tsc 坚持我们应该导入它:
import * as THREE from 'three';
它编译时没有任何问题,但是当我启动应用程序时它崩溃了,因为它试图再获取一个 THREE.js 实例,我没有提供它,因为我在主应用程序中拥有它。
如何声明正确的引用并将类型保存到主要 JavaScript 应用程序可用的命名空间?
【问题讨论】:
标签: javascript typescript three.js autodesk-forge autodesk-viewer