type-plus
Version:
Provides additional types for TypeScript.
20 lines • 865 B
JavaScript
;
// 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.brand = void 0;
const is_type_js_1 = require("../type-guard/is_type.js");
const constants_js_1 = require("./constants.js");
function brand(typeInput, subject) {
if (subject === undefined)
return function (subject) {
return brand(typeInput, 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] = typeInput;
}
return subject;
}
exports.brand = brand;
//# sourceMappingURL=brand.js.map