Type Alias IsPrimitiveString<T>

IsPrimitiveString<T>: ("random string that no one should ever get randomly" & T) extends ""
    ? false
    : true

Determines if a type is a primitive string.

Works by checking the intersection of T with a random string.

  • If T is a primitive string, the intersection will be the first random string, which does not extend "".
  • If T is is any other type, the intersection will be never. For some reason, never extends any type.

Type Parameters

  • T

    The type to check.

type Test1 = IsPrimitiveString<string>; // true
type Test2 = IsPrimitiveString<"asdf">; // false
type Test3 = IsPrimitiveString<number>; // false