leaningtech / cheerp-meta

Cheerp - a C/C++ compiler for Web applications - compiles to WebAssembly and JavaScript
https://labs.leaningtech.com/cheerp
Other
1.02k stars 50 forks source link

Suggestion: emit TypeScript type declarations #146

Closed bates64 closed 6 months ago

bates64 commented 1 year ago

Fairly large feature I expect but it'd be awesome if you could pass a flag to clang++ to generate TypeScript declarations for the module.

e.g.

clang++ -target cheerp-wasm file.c -o file.js -cheerp-make-types=file.d.ts

To emit a file.d.ts looking something like:

export type InstanciateOptions = {
    buffer: /* some typed array */,
} | {
    absPath: string | URL,
}

export default function instanciate(options: InstanciateOptions?): Promise<{}>

(And for [jsexport]'d things, export types for those funcs)

DutChen18 commented 6 months ago

Added in https://github.com/leaningtech/cheerp-compiler/pull/162