type-fns
Version:
A set of types, type checks, and type guards for simpler, safer, and easier to read code.
29 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
describe('HasMetadata', () => {
it('should enable accessing an optional metadata property of a type', () => {
const pot = { id: 123, age: 72 };
expect(pot.id.toFixed).toBeDefined(); // no type errors
});
});
describe('OmitMetadata', () => {
it('should prevent specifying a metadata property of a type', () => {
// @ts-expect-error - should not be able to set id
const pot = { id: 123, age: 72 };
});
it('should prevent accessing a metadata property of a type', () => {
const pot = { age: 72 };
// @ts-expect-error - should not be able to get id
expect(pot.id).not.toBeDefined();
});
});
describe('hasMetadata', () => {
it('should enable accessing an optional metadata property of a type', () => {
const pot = { id: 123, age: 72 };
if (!(0, __1.hasMetadata)(pot, ['id']))
throw new Error('doesnt have metadata');
expect(pot.id.toFixed).toBeDefined();
});
});
//# sourceMappingURL=hasMetadata.test.js.map