Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 1.39 KB

types.basetypeimpl.literal.md

File metadata and controls

39 lines (25 loc) · 1.39 KB

Home > @skunkteam/types > BaseTypeImpl > literal

BaseTypeImpl.literal() method

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;

Parameters

Parameter Type Description
input DeepUnbranded<ResultType> the input value to parse and validate

Returns:

ResultType

Remarks

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,
});