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
when we have content type that has a group, in advance settings we can add Set Maximum Limit for it.
By doing so it will create a tuple for that field instead of an Array.
for instance
will result following code which is wrong, because there might be no button or 1 or 2 or at max 3 buttons. Where as this type suggests there will be always 3 buttons.
buttons?: [{/** Button text */button_text: string;/** External URL */button_url?: string;/** Open link in a new tab */open_link_in_new_tab?: boolean;},{/** Button text */button_text: string;/** External URL */button_url?: string;/** Open link in a new tab */open_link_in_new_tab?: boolean;},{/** Button text */button_text: string;/** External URL */button_url?: string;/** Open link in a new tab */open_link_in_new_tab?: boolean;}];
one work around is to add a utility type that mimics the expected behaviour
type BuildTuple<T, N extends number, R extends T[] = []> =
R['length'] extends N ? R : BuildTuple<T, N, [...R, T]>;
// Recursively produce a union of all prefixes of a tuple
type TuplePrefixes<T extends any[]> =
T extends [any, ...infer Rest] ? T | TuplePrefixes<Rest extends any[] ? Rest : []> : [];
// The utility type: union of tuples with 0 to N copies of T
type MaxTuple<T, N extends number> = TuplePrefixes<BuildTuple<T, N>>;
// then it would become like this
buttons?: MaxTuple<
{
/** Button text */
button_text: string;
/** External URL */
button_url?: string;
/** Open link in a new tab */
open_link_in_new_tab?: boolean;
}, 3>
The text was updated successfully, but these errors were encountered:
when we have content type that has a group, in advance settings we can add Set Maximum Limit for it.
By doing so it will create a tuple for that field instead of an Array.
for instance
will result following code which is wrong, because there might be no button or 1 or 2 or at max 3 buttons. Where as this type suggests there will be always 3 buttons.
one work around is to add a utility type that mimics the expected behaviour
The text was updated successfully, but these errors were encountered: