es-mapping-ts
es-mapping-ts copied to clipboard
Mapping exception when extending another class and not adding @EsField() to child class
Minimal way to reproduce:
@EsEntity()
export class A {
@EsField({ type: 'text' })
a: string;
}
@EsEntity()
export class B extends A {
b: string;
}
When you run it, you will have the following exception:
const currentMappingProperty = mapping.properties.get(propertyName);
^
TypeError: Cannot read property 'properties' of undefined
at mergeProperties
It happens because it tries to access properties of the child class, but it just doesn't have any defined mapping properties. Can be fixed by adding a placeholder property to child class and decorate it with @EsField()
, but I think it would be better if the service itself understood that there is no properties in the child class and didn't try to get them.