type-fns
Version:
A set of types, type checks, and type guards for simpler, safer, and easier to read code.
44 lines • 1.75 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
describe('PickOne', () => {
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
const findWrench = (_a) => __awaiter(void 0, [_a], void 0, function* ({}) {
// ...
});
// you can find by metric
yield findWrench({
size: {
metric: { millimeters: 16 },
},
});
// you can find by imperial
yield findWrench({
size: {
imperial: { inches: '5/16' },
},
});
// you can't find by both
yield findWrench({
// @ts-expect-error - cant be both
size: {
metric: { millimeters: 16 },
imperial: { inches: '5/16' },
},
});
// you can't find by neither
yield findWrench({
// @ts-expect-error - cant be neither
size: {},
});
}));
});
//# sourceMappingURL=PickOne.test.js.map