Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ambiguous WASM type defination #16

Open
hermet opened this issue May 24, 2024 · 0 comments
Open

Improve ambiguous WASM type defination #16

hermet opened this issue May 24, 2024 · 0 comments
Labels
enhancement Improve features

Comments

@hermet
Copy link
Member

hermet commented May 24, 2024

As a Type supported web standard component, @thorvg/lottie-player should support the explicit type defination.

lottie-player.ts

There is no module type, the TvgModule is just any type. We have no benefit to take TvgModule.
As we can see in the comment, WASM Glue code didn't have type here. In fact, the Emscripten is able to provide type defination.

// @ts-ignore: WASM Glue code doesn't have type & Only available on build progress
import Module from '../dist/thorvg-wasm';
// ...
type TvgModule = any;

see: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#typescript-definitions

tvgWasmLottieAnimation

The emscripten::val is too ambiguous for TypeScript dev. Although the val is flexible and easier to bind, the compiler would map this to TypeScript's any type by default.

TypeScript developer could struggle without type, and emscripten::register_type surely helps this point.

val duration()
{
    if (!canvas || !animation) return val(0);
    return val(animation->duration()); // Actually no-type here
}

see: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#custom-val-definitions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve features
Projects
Status: No status
Development

No branches or pull requests

1 participant