UNPKG

type-plus

Version:
16 lines 710 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 brand(typeInput, subject) { if (subject === undefined) return function (subject) { return brand(typeInput, 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] = typeInput; } return subject; } //# sourceMappingURL=brand.js.map