35252-medium-isalphabet

Back

type Alphabet = | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';

type AlphabetUppercase = | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';

type AlphabetAll = Alphabet | AlphabetUppercase;

type IsAlphabet = S extends AlphabetAll ? true : false

Solution by mxniliuc #37555

妙!

type IsAlphabet<S extends string> = Uppercase<S> extends Lowercase<S> ? false : true;

Solution by djdidi #37238

type IsAlphabet<S extends string> = Uppercase<S> extends Lowercase<S> ? false : true;

Solution by gangnamssal #35933

type IsAlphabet<S extends string> = Uppercase<S> extends Lowercase<S> ? false : true;

Solution by E-uler #35336

type IsAlphabet<S extends string> = Lowercase<S> extends Uppercase<S> ? false : true

Solution by DevilTea #35312

type IsAlphabet<S extends string> = Uppercase<S> extends Lowercase<S> ? false : true

Playground

type IsAlphabet<S extends string> = (
  & Record<`${any}${S & `${any}${any}`}${any}`, true>
  & Record<string, false>
)['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'];

Playground

Solution by teamchong #35257