Recognize property with name defined by constant in Object.defineProperty #38115
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
defineProperty
#28694 is touching same domain
Suggestion
(Note: I'm using TS in JS files, have basically no knowledge about "pure" TS)
Compiler should recognize prototype property added using Object.defineProperty with name defined not only by string constant but also a string variable, e.g.:
Playground Link
(included also desired behavior for decorators, but as it's experimental feature, you won't propably even consider it)
I understand it's not always possible to make sure variable with property name is not reassigned during runtime, but it seems that TS compiler can handle detection of "static" variables that have known value during compilation.
Use Cases
This way we could define class properties using "single source" and not duplicating code. For example a class providing access to key-value pairs object in a dotted notation instead of string values for keys, whilst the object can be used for another purpose.
Examples
Playground Link
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: