Usage
import { checkExactShape, ExactShape } from '@arthurka/ts-utils';
const tooFew = { name: 'Stefan' };
const exact = { name: 'Stefan', age: '31' };
const tooMany = { name: 'Stefan', age: '31', sex: 'male' };
const record: Record<string, string> = {};
type R = typeof record;
type Exact = typeof exact;
interface ExtendedRecord extends Exact, R {}
const extendedRecord: ExtendedRecord = {
name: 'Stefan',
age: '31',
sex: 'male',
};
type Person = {
name: string;
age: string;
};
function savePerson<T extends Person>(e: ExactShape<Person, T>) {
}
savePerson(exact);
savePerson(tooFew);
savePerson(tooMany);
savePerson(record);
savePerson(extendedRecord);
function getPerson(): Person {
const e = exact;
checkExactShape<Person>()(e);
return e;
}
const person = getPerson();
console.info(person);