打字稿无法扩展 Autodesk.Viewing.ToolInterface

Typescript cannot extends Autodesk.Viewing.ToolInterface

我正在按照 Autodesk 的教程创建新的查看器工具,但使用的是 Typescript。但是,当我尝试扩展 ToolInterface 时,我得到了:

TS2689 (TS) 无法扩展接口 'Autodesk.Viewing.ToolInterface'。您是说 'implements' 吗?

如果我使用 implements 错误消失,但是我不能在构造函数中使用 super() ,如教程所述。我可以得到一些帮助吗? 在forge-viewer的index.d.ts中,ToolInterface被定义为Interface,而不是Class

这是我正在关注的教程:

https://forge.autodesk.com/blog/custom-tools-forge-viewer

正如有人在评论中正确解释的那样,Autodesk.Viewing.ToolInterface 实际上是 class。 TypeScript definition 错误地将其定义为接口,这导致了问题。

我们需要更新 TypeScript def,但与此同时,您可以尝试将自己的工具定义为一个简单的 class,不扩展或实现任何东西,并且在向查看器注册工具时使用viewer.toolController.registerTool,你可以强制输入任何你需要的类型,例如:

viewer.toolController.registerTool(myTool as Autodesk.Viewing.ToolInterface);