ts-cast
Version:
Runtime typechecking
10 lines (9 loc) • 466 B
JavaScript
import { casterApi } from '../engine';
import { throwTypeError } from '../engine/throw-type-error';
const castUndefined = (value, context, reportError = throwTypeError) => {
if (value === undefined)
return undefined;
return reportError(`undefined is expected${context ? ` in ${context}` : ''} but "${value}" received.`, context);
};
Object.defineProperty(castUndefined, 'name', { value: 'undefined' });
export const undef = casterApi(castUndefined);