Created
August 7, 2021 11:42
-
-
Save tonyonodi/656ffa655e7208772e368e25e9700ba7 to your computer and use it in GitHub Desktop.
Not very useful implementation of Char in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chartag = Symbol("char"); | |
export type Char = string & { __tag: typeof chartag }; | |
type IsChar<S extends string> = S extends `${infer Head}${infer Tail}` | |
? Head extends "" | |
? never | |
: Tail extends "" | |
? Char | |
: never | |
: never; | |
type C = IsChar<"c">; // Char | |
type CC = IsChar<"cc">; // never | |
type EC = IsChar<"">; // never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment