Description
Is your feature request related to a problem? Please describe.
There are various common utility types that aren't available in TypeScript's built-in libraries. For example:
export type NonEmptyArray<T> = [T, ...T[]]
export function isNonEmptyArray<T>(arr: T[]): arr is NonEmptyArray<T> {
return arr.length > 0
}
In some cases, these can be somewhat complex, in others (like NonEmptyArray
) implementation is somewhat trivial, but also involves design decisions where the tradeoffs may not be initially obvious — for example, what if anything is the practical difference between [T, ...T[]]
vs T[] & { 0: T }
?
Describe the solution you'd like
Maybe a new @std/types
package scope? That would be the first place I'd look for this kind of thing.
The only existing examples I know of in std are ExpandRecursively
under collections/deep-merge
, but there may be a few more.
Describe alternatives you've considered
Include type utils distributed in various other packages, but that's likely to be less discoverable — I only stumbled upon ExpandRecursively
by accident after re-implementing similar logic multiple times.