Conversation
I am testing Typescript 7's JS support, which I've largely rewritten during the switch to Go. The new code doesn't support old, Closure-derived syntax, such as uninitialised class property declarations, which VFileMessage uses. I made the smallest syntactic change to fix this, which is to initialise all the optional properties declared this way with `undefined`. The other two ways I thought of are: 1. Declare these properties as class properties in the body of the class. This splits the properties up in a non-obvious way though. 2. Declare an interface type in a separate .d.ts file and merge that with VFileMessage so Typescript thinks they are there without changing the runtime shape of VFileMessage. I can't think of the JS syntax to make this merge happen, though. Other options are: 3. Do nothing, don't update to TS7. 4. Switch to .ts, add a build step to strip types. I don't know how VFileMessage is used; having a consistent runtime shape by virtue of using class property declarations or initialising all properties to undefined generally means: faster performance, but more memory usage. I suspect it doesn't matter because people aren't creating millions of these objects per second, but I don't really know. Because TS7 is quite a way off, I don't know whether you'll want to take this PR. I created it to see how hard it would be to update popular JS code that uses TS for checking.
This comment has been minimized.
This comment has been minimized.
|
Hi there! Thanks for working on the ecosystem! Using JS instead of TS is intentional for me. Method 3, of using These things are just to document the fields: they are indeed never set by us, but ecosystem users may set and use them.
@sandersn, what’s the clever code here you mention? |
|
I figured that adding a tsc build was not something you wanted. The types.d.ts file I added is effectively a shim to inject types for Typescript to work with without changing anything at runtime. But I am stuck with .d.ts to do this because there's no equivalent jsdoc that Typescript understands. The clever code I noticed is the If there aren't millions of these objects being created I think I'd go with the |
|
I like option 2 or 3. This is how most people would normally write a class. This class isn’t that special I think. I never really understood the purpose of the |
|
I reverted to the simple change with initialisers in the constructor. To make tests pass, I changed the initial value of |
This comment has been minimized.
This comment has been minimized.
|
Thanks, released in |
Initial checklist
Description of changes
I am testing Typescript 7's JS support, which I've largely rewritten during the switch to Go. The new code doesn't support old, Closure-derived syntax, such as uninitialised class property declarations, which VFileMessage uses.
There are multiple ways to fix this. I went for the one that changes only types, with no runtime effects.
actualandexpected.undefinedor''initialisers to the optional properties. This also changes the shape of the class at runtime.Other options are:
I don't know how VFileMessage is used; having a consistent runtime shape by virtue of using class property declarations or initialising all properties to undefined generally means: faster performance, but more memory usage. This only matters in cases where people are creating millions of these objects per second. I avoided that change this time, though, because the documentation explicitly mentions that the properties I changed are optional, and the code has some clever manipulation of the prototype to avoid setting
fileon every object.Because TS7 is quite a way off, I don't know whether you'll want to take this PR. I created it to see how hard it would be to update popular JS code that uses TS for checking.
Edit: the first commit uses method (3), which is a smaller code change and a bigger runtime change.