Open shellscape opened 1 year ago
Consider the following:
const ActionWildcardStruct = size(array(literal('*')), 1); export type ActionWildcard = Infer<typeof ActionWildcardStruct>;
That Infer produces a type of type ActionWildcard = "*"[]. While that's correct, it's overly permissive given the size constraints. Instead, we could use something like this:
Infer
type ActionWildcard = "*"[]
size
// Lifted from: https://stackoverflow.com/questions/41139763/how-to-declare-a-fixed-length-array-in-typescript type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | number; type ArrayItems<T extends any[]> = T extends Array<infer TItems> ? TItems : never; type FixedLengthArray<T extends any[]> = Pick<T, Exclude<keyof T, ArrayLengthMutationKeys>> & { [Symbol.iterator]: () => IterableIterator<ArrayItems<T>>; };
And the Infer result could then be:
type ActionWildcard = FixedLengthArray<['*']>
That would be much more restrictive and true to the intent of the use of size.
Consider the following:
That
Infer
produces a type oftype ActionWildcard = "*"[]
. While that's correct, it's overly permissive given thesize
constraints. Instead, we could use something like this:And the
Infer
result could then be:That would be much more restrictive and true to the intent of the use of
size
.