Determines whether the specified suspect type satisfies the restriction of the given type description (TD).
Entity of unknown type to be tested for conformance according to TD.
If it is a basic JavaScript typename string (should satisfy typeof operator
domain definition), then function returns typeof suspect === typeDescr
.
If it is a RegExp
, then returns
typeof suspect === 'string' && typeDescr.test(suspect)
.
Else if it is a Set
Checks whether suspect conforms to the given type description and returns it if yes, otherwise returns the default value.
Type description suspect may conform to,
defaultVal
MUST conform to this TD.
Value of unknown type to provide default value for.
Value that conforms to typeDescr
TD that is
returned by this function if !conforms(suspect, typeDescr)
.
Same as mismatch(suspect, typeDescr)
but allows suspect
object with
excess properties to pass the match.
Value of unknown
type to be tested for conformance to typeDescr
.
TypeDescription
that describes limitations that must be
applied to suspect
to pass the match (see conforms()
for
more info about the structure of TypeDescription
).
This function returns nothing. It throws TypeMismatchError
if its suspect
failed to match to the given typeDescr
by executing
duckMismatch(suspect, typeDescr)
.
This function returns nothing. It throws TypeMismatchError
if its suspect
failed to match to the given typeDescr
by executing
mismatch(suspect, typeDescr)
.
Same as conforms()
, but returns false for suspect object that has
excess properties (those, that are not present in type description object).
Entity of unknown type to be tested for conformance according to TD.
TypeDescription
that describes limitations that must be
applied to suspect
to pass the match (see conforms()
for
more info about the structure of TypeDescription
).
Returns a new TypeDescrObjMap
(which is assignable to TypeDescription
)
object that is composed of typeDescr
properties wrapped as
result[propName] = optional(typeDescr[propName])
for each propName in typeDescr
own property names.
Type of TD object, i.e an object with values of TypeDescription
type.
Object to make new TypeDescrObjMap
with all optional properties from.
Returns a MismatchInfo
object that stores an information about type
incompatability for the given typeDescr
.
Value of unknown
type to be tested for conformance to typeDescr
.
TypeDescription
that describes limitations that must be
applied to suspect
to pass the match (see conforms()
for
more info about the structure of TypeDescription
).
C++ style operator, a syntactic sugar for writing casts like
value as any as T
when a simple value as T
cast cannot be performed.
Use it with caution!
value to cast by any means to T.
Takes given properties from the object and returns them as a new object.
Source object to take data from.
Array of property names to include to the returend object.
New object that is a shallow copy of sourceObject
with the properties given as propertyNames
array.
The same as take(sourceObject, Object.getOwnPropertyNames(keysObject))
,
but with stronger typing.
TypeScript type guard that always returns true.
Target value, to make type assertion of.
Generated using TypeDoc
This function is no-op, but it is useful to check whether you have handled all the cases and some code path is unreachable.
TypeScript compiler will issue an error if you forward a value not of never type to this function.
import * as Vts from 'vee-type-safe'; const enum Enum { A, B, C } function fn(en: Enum) { switch (en) { case Enum.A: { return; } case Enum.B: { return; } default: { Vts.assertNever(en); // compile Error, en is of type Enum.C } } } //------------- const num = 23; if (typeof num !== 'number'){ Vts.assertNever(num); // no error, this code is unreachable // num is of type never here }