Options
All
  • Public
  • Public/Protected
  • All
Menu

Package new-type

@typed/new-type

New types for TypeScript

Index

Type aliases

Base

Base<A>: A extends NewType<infer R, any> ? R : never

Get the underlying type of a NewType

Type parameters

Character

Character: NewType<string & { length: 1 }, "Character">

Combine

Combine<A, B>: A extends NewType<infer AB, infer AT> ? B extends NewType<infer BB, infer BT> ? NewType<AB | BB, AT & BT> : never : never

Type parameters

  • A

  • B

EmptyString

EmptyString: NewType<string & { length: Zero }, "EmptyString">

Integer

Integer: NewType<number, "Integer">

Negative

Negative: NewType<number, "Negative">

NegativeInteger

NegativeInteger: Combine<Negative, Integer>

NewType

NewType<A, Type>: A & { __TYPE__: Type }

Helper type for creating ad-hoc new types

Type parameters

  • A

  • Type

NonEmptyString

NonEmptyString: NewType<string & { length: PositiveInteger }, "NonEmptyString">

NonNegative

NonNegative: Zero | Positive

NonNegativeInteger

NonNegativeInteger: Zero | PositiveInteger

NonPositive

NonPositive: Zero | Negative

NonPositiveInteger

NonPositiveInteger: Zero | NegativeInteger

NonZero

NonZero: NewType<number, "NonZero">

NonZeroInteger

NonZeroInteger: Combine<NonZero, Integer>

Positive

Positive: NewType<number, "Positive">

PositiveInteger

PositiveInteger: Combine<Positive, Integer>

TypeName

TypeName<A>: A extends NewType<any, infer R> ? R : never

Get type name from a NewType

Type parameters

Zero

Zero: NewType<number, "Zero">

Variables

Const isCharacter

isCharacter: (Anonymous function) = isNewType((x: string): x is Character => x.length === 1)

Const isEmptyString

isEmptyString: (Anonymous function) = isNewType((x: string): x is EmptyString => x === '')

Const isInteger

isInteger: (Anonymous function) = isNewType<number, Integer>((n): n is Integer => Number.isInteger(n))

Const isNegative

isNegative: (Anonymous function) = isNewType((x: number): x is Negative => x < 0)

Const isNegativeInteger

isNegativeInteger: (Anonymous function) = isNewType((n: number): n is NegativeInteger =>_isNegativeInteger(n),)

Const isNonEmptyString

isNonEmptyString: (Anonymous function) = isNewType((x: string): x is NonEmptyString => x !== '')

Const isNonNegative

isNonNegative: (Anonymous function) = isNewType((x: number): x is NonNegative => _isNonNegative(x))

Const isNonNegativeInteger

isNonNegativeInteger: (Anonymous function) = isNewType((n: number): n is NonNegativeInteger =>_isNonNegativeInteger(n),)

Const isNonPositive

isNonPositive: (Anonymous function) = isNewType((n: number): n is NonPositive => _isNonPositive(n))

Const isNonPositiveInteger

isNonPositiveInteger: (Anonymous function) = isNewType((n: number): n is NonPositiveInteger =>_isNonPositiveInteger(n),)

Const isNonZero

isNonZero: (Anonymous function) = isNewType((x: number): x is NonZero => x !== 0)

Const isNonZeroInteger

isNonZeroInteger: (Anonymous function) = isNewType((x: number): x is NonZeroInteger => _isNonZeroInteger(x))

Const isPositive

isPositive: (Anonymous function) = isNewType((x: number): x is Positive => x > 0)

Const isPositiveInteger

isPositiveInteger: (Anonymous function) = isNewType((n: number): n is PositiveInteger =>_isPositiveInteger(n),)

Const isZero

isZero: (Anonymous function) = isNewType((x: number): x is Zero => x === 0)

Functions

Const isNewType

  • isNewType<A, B>(refinement: (value: A) => value is B): (Anonymous function)
  • Validate a NewType

    Type parameters

    Parameters

    • refinement: (value: A) => value is B
        • (value: A): value is B
        • Parameters

          • value: A

          Returns value is B

    Returns (Anonymous function)

    :: boolean

Const unsafeCoerce

  • unsafeCoerce<A>(value: Base<A>): A

Generated using TypeDoc