propylons-client
Version:
Client package for Propylons
32 lines • 1.17 kB
JavaScript
;
/*!
* Propylons
* Copyright(c) 2022 Xavier Raffin
* MIT Licensed
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyTypeMismatchError = exports.MissingPropertyError = exports.assertFieldType = void 0;
/**
* Assert member name and type or throw
*
* @param object object to assert on
* @param fieldName name of the field to check the presence of
* @param fieldType type of the field to check
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function assertFieldType(object, fieldName, fieldType) {
if (!(fieldName in object)) {
throw new MissingPropertyError(`Missing property ${fieldName}`);
}
if (typeof object[fieldName] !== fieldType) {
throw new PropertyTypeMismatchError(`Property ${fieldName} is of type ${typeof object[fieldName]} but (${fieldType} was expected)`);
}
}
exports.assertFieldType = assertFieldType;
class MissingPropertyError extends Error {
}
exports.MissingPropertyError = MissingPropertyError;
class PropertyTypeMismatchError extends Error {
}
exports.PropertyTypeMismatchError = PropertyTypeMismatchError;
//# sourceMappingURL=TypeChecker.js.map