I'm trying to learn TS and I came to a weird case scenario.
I have an object with a property set as non-enumerable:
let person = {
name: 'Harry'
}
Object.defineProperty(person,'salary',{enumerable: false, value : 15});
console.log(person.salary); // 15
This works at runtime, however, the compiler is going to error:
Property 'salary' does not exist on type '{ name: string; }'
which is expected.
I could bypass this setting the type of person as any, but it doesn't feel like a clean solution.
Is there another way to do it? The non-null assertion operator doesn't work for this.
I'd appreciate if anyone can share some knowledge about this.