Default attributes warning

This commit is contained in:
barsdeveloper
2022-05-01 12:54:55 +02:00
parent fcf1bbf32c
commit 2617e15691
5 changed files with 51 additions and 26 deletions

View File

@@ -19,11 +19,17 @@ export default class IEntity {
Object.getOwnPropertyNames(properties),
Object.getOwnPropertyNames(values ?? {})
)) {
if (!(property in properties)) {
console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`)
}
let defaultValue = properties[property]
const defaultType = Utility.getType(defaultValue)
if (!(property in properties)) {
console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`)
} else if (
defaultValue != null
&& !(defaultValue instanceof TypeInitialization && !defaultValue.showDefault)
&& !(property in values)
) {
console.warn(`${this.constructor.name} adds property ${prefix}${property} not defined in the serialized data`)
}
// Not instanceof because all objects are instenceof Object, exact match needed
if (defaultType === Object) {
target[property] = {}