-
-
Notifications
You must be signed in to change notification settings - Fork 679
CastArray type #1392
Copy link
Copy link
Closed
Labels
Description
Type description + examples
CastArray is the return type of this util function:
const castArray = <T>(value: T | T[]): T[] => {
return Array.isArray(value) ? value : [value];
};
import type { CastArray } from 'type-fest';
type Foo = string;
type FooArr = string[];
type CastFoo = CastArray<Foo>; // -> string[];
type CastFooArr = CastArray<FooArr>; // -> string[]Type source
Could be something like this. Not completely sure if this covers all edge cases someone might want to use this for. For example if you want the return type [T] instead of T[]
type CastArray<T> = T extends any[] ? T : T[];Search existing types and issues first
- I tried my best to look for it
Reactions are currently unavailable