Bigint
The bigint category identifies bigint and bigint literals, and casts a string literal to a bigint
literal. The predicates follow the usual type branching contract, so
each one can act as a boolean check, as a filter, or as a branch selector for your own types.
For arithmetic over bigint, see Math. Every math type accepts number or bigint.
IsBigint and IsNotBigint
Section titled “IsBigint and IsNotBigint”type IsBigint<T, $O extends $StrictOptions<$O, IsBigint.$Options> = {}>type IsNotBigint<T, $O extends $StrictOptions<$O, IsNotBigint.$Options> = {}>🎭 predicate — is T bigint or a bigint literal.
type R1 = IsBigint<bigint> // truetype R2 = IsBigint<1n> // truetype R3 = IsBigint<string | boolean> // falsetype R4 = IsBigint<string | bigint> // boolean, distributedtype R5 = IsNotBigint<1n> // falseBoth support selection: 'filter', exact: true, distributive: false, and the $any / $unknown /
$never / $void branch overrides. See type branching.
type R6 = IsBigint<1n, { exact: true }> // false — `1n` is not exactly `bigint`type R7 = IsBigint<1n, { selection: 'filter' }> // 1ntype R8 = IsBigint<string | bigint, { distributive: false }> // falseIsBigintLiteral and IsNotBigintLiteral
Section titled “IsBigintLiteral and IsNotBigintLiteral”type IsBigintLiteral<T, $O extends $StrictOptions<$O, IsBigintLiteral.$Options> = {}>type IsNotBigintLiteral<T, $O extends $StrictOptions<$O, IsNotBigintLiteral.$Options> = {}>Narrower than IsBigint: only bigint literals pass.
type R1 = IsBigintLiteral<1n> // truetype R2 = IsBigintLiteral<bigint> // falsetype R3 = IsNotBigintLiteral<bigint> // truetype R4 = IsNotBigintLiteral<1n | string, { selection: 'filter' }> // stringThey already answer the literal question, so they do not take exact; passing it is a compile error.
StringToBigint
Section titled “StringToBigint”type StringToBigint<S extends string, $O extends $StrictOptions<$O, StringToBigint.$Options> = {}>Casts a string literal to a bigint literal when the string is a valid bigint form, which needs the
n suffix. NumericToString casts the other way and keeps the suffix; see
the number casts.
type R1 = StringToBigint<'1n'> // 1ntype R2 = StringToBigint<'-1n'> // -1ntype R3 = StringToBigint<'abc'> // never