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

#164 updated glam & bevy_ecs types to match their serde implementation #165

Conversation

bennobuilder
Copy link
Contributor

No description provided.

@bennobuilder
Copy link
Contributor Author

Would it be possible to generate like:

export type Vec2 = [number, number]

instead of

export type Vec2 = number[]

number[] is good enough but like [number, number] would be even more typesafe :)

@oscartbeaumont
Copy link
Member

oscartbeaumont commented Oct 26, 2023

You could try (i32, i32) or [i32; 2]?

If it's not clear with Serde transparent the first one will be struct Demo((i32, i32)); not struct Demo(i32, i32).

@bennobuilder
Copy link
Contributor Author

You could try (i32, i32) or [i32; 2]?

If it's not clear with Serde transparent the first one will be struct Demo((i32, i32)); not struct Demo(i32, i32).

Ok (f32, f32) seems to work:

#[derive(Type)]
#[specta(remote = glam::Vec2, crate = crate, export = true)]
#[allow(dead_code)]
struct Vec2((f32, f32));

Result:

export type Vec2 = [number, number]

With [f32; 2] (as its rn implemented) it results in number[] though.

#[derive(Type)]
#[specta(remote = glam::Vec2, crate = crate, export = true)]
#[allow(dead_code)]
struct Vec2([f32; 2]);

Result:

export type Vec2 = number[]

so I'll change that quickly into a tuple :)

@oscartbeaumont
Copy link
Member

As of 7039fba we now support [T; N] as a fixed size Typescript tuple.

@oscartbeaumont oscartbeaumont merged commit 3a3f4bf into specta-rs:main Nov 22, 2023
@oscartbeaumont
Copy link
Member

Thanks heaps for the PR!

@bennobuilder bennobuilder deleted the 164-update-specta-implementation-for-glam-and-bevy-ecs-types-baded-on-serialization-format branch November 22, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Specta Implementation for glam & bevy_ecs Types based on Serialization Format (serde)
2 participants