You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since we have to cast our inputs variable as const, there's nothing to keep us from mistyping an input. Seems like we're basically trading type safety for the Builder inputs with type safety for our custom components. It would be nice if this lib exported a helper to have the best of both worlds.
Here's one way that seems to work:
importtype{Input}from'@builder.io/sdk';// Readonly only goes one level deep, so we need our own utility typetypeDeepReadonly<T>=Textends(infer R)[] ? DeepReadonlyArray<R> :
TextendsFunction ? T :
Textendsobject ? DeepReadonlyObject<T> :
T;interfaceDeepReadonlyArray<T>extendsReadonlyArray<DeepReadonly<T>>{}typeDeepReadonlyObject<T>={readonly[PinkeyofT]: DeepReadonly<T[P]>;};constinputs=[{name: 'tabs',type: 'list',subFields: [{name: 'label',type: 'text',defaultValue: 'New tab',},{name: 'content',type: 'uiBlocks',defaultValue: [],},],defaultValue: [{label: 'Tab 1',content: [],},],},]asconstsatisfiesDeepReadonly<Input[]>;
Maybe we could export type BuilderInputs = DeepReadOnly<Input[]> so users can just do as const satisfies BuilderInputs?
The text was updated successfully, but these errors were encountered:
Hmmm, I would definitely like to explore this. Would you mind submitting a PR? I'll give it a spin and released it under a next tag then get some feedback from a couple projects I know that are using this utility. :)
Since we have to cast our inputs variable
as const
, there's nothing to keep us from mistyping an input. Seems like we're basically trading type safety for the Builder inputs with type safety for our custom components. It would be nice if this lib exported a helper to have the best of both worlds.Here's one way that seems to work:
Maybe we could
export type BuilderInputs = DeepReadOnly<Input[]>
so users can just doas const satisfies BuilderInputs
?The text was updated successfully, but these errors were encountered: