UNPKG

type-plus

Version:
20 lines 856 B
"use strict"; // By Drew Colthorp, <https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/#comment-604580> // <https://gist.github.com/dcolthorp/aa21cf87d847ae9942106435bf47565d> Object.defineProperty(exports, "__esModule", { value: true }); exports.flavor = void 0; const is_type_js_1 = require("../type-guard/is_type.js"); const constants_js_1 = require("./constants.js"); function flavor(type, subject) { if (subject === undefined) return function (subject) { return flavor(type, subject); }; if ((0, is_type_js_1.isType)(subject, s => typeof s === 'object' && s !== null)) { // if subject is not an object, the branding will exist only in type-level. subject[constants_js_1.typeSym] = type; } return subject; } exports.flavor = flavor; //# sourceMappingURL=flavor.js.map