ts-type
Version:
add some typescript type and re-export some build-in typescript type
9 lines (8 loc) • 333 B
TypeScript
/**
* detect if T is a union
*/
export type IsAUnion<T, Y = true, N = false, U = T> = U extends any ? ([T] extends [U] ? N : Y) : never;
/**
* detect if T is a single string literal
*/
export type IsASingleStringLiteral<T extends string, Y = true, N = false> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;