I created a custom forge extension and now I am looking to incorporate typescript support as outlined in this blog post. However, I am facing an issue where typescript cannot locate the objects like Autodesk.Viewing.Extension
and Autodesk.Viewing.ToolInterface
because they do not exist during transpile time. To work around this, I have implemented a solution where I pass the parameter Autodesk
through a factory function when creating the Extension class (see code example) due to the inability to access the global Autodesk variable from within an ES6 module. This workaround results in losing all type information.
Is there a way to fully integrate typescript into my custom extension?
My current workaround:
function(Autodesk: any) { // injects Autodesk by passing the global accessible Autodesk object...
return class MyExtension extends Autodesk.Viewing.Extension {
...
};
}
Desired outcome (with typescript support):
class MyAwesomeExtension extends Autodesk.Viewing.Extension {
constructor(viewer, options) {
super(viewer, options);
}
load() {
console.log('MyAwesomeExtensions has been loaded');
viewer.setEnvMapBackground(null); // Hide background environment if there is one
viewer.setBackgroundColor(0, 64, 128); // Set background color
return true;
}
unload() {
console.log('MyAwesomeExtensions has been unloaded');
return true;
}
}
Autodesk.Viewing.theExtensionManager.registerExtension('MyAwesomeExtension', MyAwesomeExtension);