You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would love to see a compiler option for compiling TypeScript files with optional field declarations disappearing from the JavaScript class body. The current behaviour is for the fields to just be listed in the class body which leads to them being initialised to undefined per instance. This can lead to unnecessary memory bloat in some cases. I tried using the exactOptionalPropertyTypes compiler option but unfortunately it does not work for this scenario.
π Motivating Example
I am creating a reactive library using TypeScript here. An important detail about my implementation is wrapping existing objects with reactive ones. The wrapping objects have many optional fields, that should not be present at all unless they are needed to function. Typescript enforces type declarations for all members, including optional ones, so that all the properties end up getting initialised to undefined in the output JavaScript.
This is working as intended and is for compatibility with the ECMAScript standard. You can disable the behavior by turning off useDefineForClassFields.
π Search Terms
type declaration
β Viability Checklist
β Suggestion
I would love to see a compiler option for compiling TypeScript files with optional field declarations disappearing from the JavaScript class body. The current behaviour is for the fields to just be listed in the class body which leads to them being initialised to
undefined
per instance. This can lead to unnecessary memory bloat in some cases. I tried using theexactOptionalPropertyTypes
compiler option but unfortunately it does not work for this scenario.π Motivating Example
I am creating a reactive library using TypeScript here. An important detail about my implementation is wrapping existing objects with reactive ones. The wrapping objects have many optional fields, that should not be present at all unless they are needed to function. Typescript enforces type declarations for all members, including optional ones, so that all the properties end up getting initialised to undefined in the output JavaScript.
TS input:
JS output:
What I prefer:
The text was updated successfully, but these errors were encountered: