UNPKG

type-plus

Version:
16 lines 698 B
// By Drew Colthorp, <https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/#comment-604580> // <https://gist.github.com/dcolthorp/aa21cf87d847ae9942106435bf47565d> import { isType } from '../type-guard/is_type.js'; import { typeSym, valueSym } from './constants.js'; export function flavor(type, subject) { if (subject === undefined) return function (subject) { return flavor(type, subject); }; if (isType(subject, s => typeof s === 'object' && s !== null)) { // if subject is not an object, the branding will exist only in type-level. subject[typeSym] = type; } return subject; } //# sourceMappingURL=flavor.js.map