fix(core): add alias for primitive type "number"
This commit is contained in:
parent
2c5310bcc2
commit
a10c258202
@ -93,9 +93,9 @@ function coerceType(prop: PropertyDescription | undefined, value: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
} else if (prop.type == 'boolean') {
|
} else if (normalizedPrimitiveType(prop.type) == 'boolean') {
|
||||||
return value === true || value == 'true';
|
return value === true || value == 'true';
|
||||||
} else if (prop.type == 'number') {
|
} else if (normalizedPrimitiveType(prop.type) == 'number') {
|
||||||
return Number(value);
|
return Number(value);
|
||||||
} else if (prop.type == 'array') {
|
} else if (prop.type == 'array') {
|
||||||
return value
|
return value
|
||||||
@ -206,7 +206,7 @@ function validateProperty(
|
|||||||
|
|
||||||
const isPrimitive = typeof value !== 'object';
|
const isPrimitive = typeof value !== 'object';
|
||||||
if (isPrimitive) {
|
if (isPrimitive) {
|
||||||
if (typeof value !== schema.type) {
|
if (typeof value !== normalizedPrimitiveType(schema.type)) {
|
||||||
throw new SchemaError(
|
throw new SchemaError(
|
||||||
`Property '${propName}' does not match the schema. '${value}' should be a '${schema.type}'.`
|
`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) {
|
function throwInvalidSchema(propName: string, schema: any) {
|
||||||
throw new SchemaError(
|
throw new SchemaError(
|
||||||
`Property '${propName}' does not match the schema.\n${JSON.stringify(
|
`Property '${propName}' does not match the schema.\n${JSON.stringify(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user