Enhance type safety in StructuredView#7
Open
rubyquaildesign wants to merge 1 commit intogreggman:devfrom
Open
Conversation
more specific TypeDefinitions lead to stricter and more accurate type checks. Signed-off-by: Ruby Quail <ruby@rubyquail.design>
Owner
|
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. |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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