fix(core): add alias for primitive type "number"

This commit is contained in:
Victor Savkin 2020-12-21 08:47:13 -05:00
parent 2c5310bcc2
commit a10c258202

View File

@ -93,9 +93,9 @@ function coerceType(prop: PropertyDescription | undefined, value: any) {
}
}
return value;
} else if (prop.type == 'boolean') {
} else if (normalizedPrimitiveType(prop.type) == 'boolean') {
return value === true || value == 'true';
} else if (prop.type == 'number') {
} else if (normalizedPrimitiveType(prop.type) == 'number') {
return Number(value);
} else if (prop.type == 'array') {
return value
@ -206,7 +206,7 @@ function validateProperty(
const isPrimitive = typeof value !== 'object';
if (isPrimitive) {
if (typeof value !== schema.type) {
if (typeof value !== normalizedPrimitiveType(schema.type)) {
throw new SchemaError(
`Property '${propName}' does not match the schema. '${value}' should be a '${schema.type}'.`
);
@ -227,6 +227,15 @@ function validateProperty(
}
}
/**
* Unfortunately, due to use supporting Angular Devkit, we have to do the following
* conversions.
*/
function normalizedPrimitiveType(type: string) {
if (type === 'integer') return 'number';
return type;
}
function throwInvalidSchema(propName: string, schema: any) {
throw new SchemaError(
`Property '${propName}' does not match the schema.\n${JSON.stringify(