Skip to content

Conversation

rubyquaildesign
Copy link

This is super quick and I', sure if this is worth adding unless we also add the ability to type check the values rather then just the keys, but I'm working on putting together a typescript plugin which hopefully will allow typescript to access the type definitions of a script at compile/development time so with this change you could ensure that struct member names match those in the shader

more specific TypeDefinitions lead to stricter and more accurate type checks. Signed-off-by: Ruby Quail <ruby@rubyquail.design>
@greggman
Copy link
Owner

greggman commented Jan 13, 2024

Thanks for the PR!

I'm am not sure what this adds. Can you give me an example? I downloaded it locally and tried some stuff but I didn't see the difference (note, I'm not a typescript expert)

If you want something that generates types for typescript, this code might come close with a few tweaks. OTOH, that code might be missing info to fully do it.

@rubyquaildesign
Copy link
Author

const myStructDefinition = { size: 12, fields: { 'fFieldOne': { offset: 0, type:{size: 4 }, }, 'fFieldTwo': { offset: 4, type:{size: 4}, }, 'fFieldThree': { offset: 8, type:{size:4}, }, }, } satisfies StructDefinition; const myView = makeStructuredView(myStructDefinition); myView.set({ fFieldOne: 0.5, fFieldThree: .2, fFieldTwo: 0.7, fFieldFour: 12, }); // Object literal may only specify known properties, and 'fFieldFour' does not exist in type 'Partial<Record<"fFieldOne" | "fFieldTwo" | "fFieldThree", any>>'.

Effectively just provides type information to the fields if the struct definition has field information in it (which could be provided by a typescript plugin like how typescript-plugin-css-modules does for css modules, giving you autocorrect and in editor error handling for struct field names)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants