4 ms·
any is the last resort. How do you get around properties assigned via Object.defineProperties recognised by TS, though? I really don't know. Is is an unrelated
by beebeepka 4y ago
any is the last resort.
How do you get around properties assigned via Object.defineProperties recognised by TS, though? I really don't know. Is is an unrelated question
- TheCleric 4y agoHere's how I would do it: interface IOptionsX { x: number; } interface IOptionsY { y: number; } const testObj: IOptionsX = {x : 0}; Object.defineProperties(testObj, { y: { value: 100, writable: true }, }); if ('y' in testObj) { // Could also do `&& typeof testObj.y === 'number'` to be VERY sure. const testObjWithY = testObj as typeof testObj & IOptionsY; console.log(testObjWithY.y) }
- TheCleric 4y agoThough honestly I've gotten this far without EVER using defineProperty so I'd probably continue that streak.