0

I'm following a tutorial from Autodesk to create a new viewer tool, but using Typescript. However, when I tried extending ToolInterface, I got :

TS2689 (TS) Cannot extend an interface 'Autodesk.Viewing.ToolInterface'. Did you mean 'implements'?

The error disappears if I use implements, but then I cannot use super() in the constructor, as in the tutorial stated. Can I get some help on this? In the index.d.ts of forge-viewer, the ToolInterface is defined as Interface, not Class

This is the tutorial I'm following:

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

3
  • The thing called tool interface in their example is not an interface so I'm confused as to why typescript would tell you it is. You'll have to show the code you're using. Commented Apr 22, 2021 at 7:35
  • I didn't get far since that's the first line of the code. This is all I have: const ToolName = 'TransformScaleTool'; const ToolOverlayName = 'TransformScaleOverlay'; export default class TransformScaleTool implements Autodesk.Viewing.ToolInterface { state = ''; constructor() { super(); this.state = ''; } } Commented Apr 22, 2021 at 8:08
  • The project is very big so I can't send everything up here. But when I use implements for ToolInterface, Visual studio points to index.d.ts in node_modules/forge-viewer. Commented Apr 22, 2021 at 8:10

1 Answer 1

1

As someone correctly explained in the comments, Autodesk.Viewing.ToolInterface is actually a class. The TypeScript definition incorrectly defines it as an interface which is then causing issues.

We will need to update the TypeScript defs but in the meantime, you could try and define your own tool as a simple class, not extending or implementing anything, and when registering the tool with the viewer using viewer.toolController.registerTool, you could force-type it to whichever type you need, for example:

viewer.toolController.registerTool(myTool as Autodesk.Viewing.ToolInterface);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.