[Typescript] 136. Medium - NonEmptyArray

type NonEmptyArray<T> = [T, ...Array<T>];

export const makeEnum = (values: NonEmptyArray<string>) => {};

makeEnum(["a"]);
makeEnum(["a", "b", "c"]);

// @ts-expect-error
makeEnum([]);

 

The idea is that Tshould be an array type with at least one value.

posted @ 2022-12-11 22:16  Zhentiw  阅读(9)  评论(0编辑  收藏  举报