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

Feature request: Typed array types #315

Open
eye-wave opened this issue May 9, 2024 · 1 comment
Open

Feature request: Typed array types #315

eye-wave opened this issue May 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@eye-wave
Copy link

eye-wave commented May 9, 2024

Is your feature request related to a problem? Please describe.
It would be to have Integer of Float Vectors be converted to typed arrays.

example

Vec<f32> -> Float32Array
Vec<u8> -> Uint8Array
Vec<i32> -> Int32Array 

Describe alternatives you've considered
Tsify, but it only works with wasm-bindgen which i don't need for a tauri app

adding #[ts(type = "MyArray")] for each problematic property

@eye-wave eye-wave added the enhancement New feature or request label May 9, 2024
@escritorio-gustavo
Copy link
Collaborator

I'm not sure we can implement this at all.

At the moment, Vec<T> simply exports Array<T>, which is generally what the user expects, even in Tauri, as most of the time the serialization is done through serde.

We do this through a generic impl block on Vec that goes something like

impl<T: TS> TS for Vec<T> {
    // ... export T, but wrapped in Array<>
}

So we can't just write

impl TS for Vec<u8> {
    // Export as Uint8Array
}

because that would generate a compiler error complaining about conflicting trait impls.

Also, most people don't expect an Uint8Array, so even if it were allowed, we still couldn't do that easily, as it can't be the default behavior.

I do recommend that you create a type that exports as Uint8Array and use #[ts(as = "...")] instead of #[ts(type = "...")] though, as it helps avoid typos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants