Home > @skunkteam/types > BaseTypeImpl > literal
Calls any registered parsers or auto-caster, verifies that the resulting value conforms to this Type and returns it if it does.
Signature:
literal(input: DeepUnbranded<ResultType>): ResultType;
Parameter | Type | Description |
---|---|---|
input | DeepUnbranded<ResultType> | the input value to parse and validate |
Returns:
ResultType
When given a value that either cannot be parsed by the optional parser or does not conform to the Type, throws an exception.
This is the same as BaseTypeImpl.construct(), but accepts an argument that has a similar structure to the type itself, so code editors will offer code completion for this literal argument.
Example:
const User = object('User', { id: int });
const user = User.literal({
// proper code completion here
id: 1234,
});