Create a type predicate function that checks if input is an object matching the given objectShape. Set additionalProperties to false to reject objects with extra properties.
input
objectShape
additionalProperties
false
const isPerson = shape({ name: isString, age: isNumber });isPerson({ name: 'Andy', age: 30 }); // trueisPerson({ name: 'Andy' }); // falseconst isStrictPerson = shape({ name: isString, age: isNumber }, false);isStrictPerson({ name: 'Andy', age: 30, extra: true }); // false Copy
const isPerson = shape({ name: isString, age: isNumber });isPerson({ name: 'Andy', age: 30 }); // trueisPerson({ name: 'Andy' }); // falseconst isStrictPerson = shape({ name: isString, age: isNumber }, false);isStrictPerson({ name: 'Andy', age: 30, extra: true }); // false
Create a type predicate function that checks if
inputis an object matching the givenobjectShape. SetadditionalPropertiestofalseto reject objects with extra properties.