@lab900/typescript-serializer
Version:
JSON serialization/deserialization of Typescript objects
10 lines (9 loc) • 340 B
JavaScript
export function primitiveDeserializer(sourceObject, type, key) {
if (type === Number) {
sourceObject = +sourceObject;
}
if (sourceObject && (sourceObject === null || sourceObject === void 0 ? void 0 : sourceObject.constructor) !== type) {
throw Error(`Type mismatch on ${key}`);
}
return sourceObject;
}