I have a custom Node.js addon that I've written, but I'd like to use typescript. I can use bindings to import the module in JavaScript
const addon = require('bindings')('addon');
which will import addon.node from build/release/
How can I do this using TypeScript? Does it allow addon import?
You should be able to create a declaration file that adds type information for your addon module, and then import it using a relative path in TypeScript.
For good examples of declaration files for external modules, see the DefinitelyTyped GitHub repository. A succinct good example from that directory is the declaration for the camelcase
NPM nodule:
declare module "camelcase" {
function camelcase(...args: string[]): string;
namespace camelcase {}
export = camelcase;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With