Hi all, I’ve spent the past weeks adjusting the codebase to TypeScript and (the harder part) setting up the build system and tests to work well with the new build-step requirements. This means that the code is now typed using strict TypeScript, which should make it a bit easier to explore and to ensure that changes are consistent. The types even discovered a few small issues and a bit of dead code in the existing codebase.
The new code is on github. No breaking changes should have been made to the JavaScript interface. But there were a few possibly-observable adjustments:
The ES modules in the packages now contain ES6 code, and are no longer compiled down to ES5. (The CommonJS modules are still ES5.)
Source maps are no longer included in the packages. (I understand these are occasionally useful, but they bloat the package files and slow down builds, so I’ve opted to get rid of them.)
The packages now come with their own TypeScript declaration files, derived from the source code.
That last one will be the main source of potential problems. There are likely enough differences between the old, hand-written types on DefinitelyTyped and the ones created from the code to break some people’s builds. For one thing, I decided against including a Schema type parameter in pretty much every type in the system, to make the types more readable and straightforward. I expect most people were defaulting that to any already, since it’d be a major pain to correctly track that throughout your code, but if you didn’t, you’ll have to adjust your types.
All the updated packages are released to npm under a beta tag, to give people a chance to migrate to them and provide feedback. Again, I don’t intend to be 100% compatible with the old types, and some porting will likely be required, but if there’s something that looks wrong or unnecessarily awkward, let me know, and I’ll see if I can fix it.
(Hey, don’t blame me for this kind of breakage—blame TypeScript’s system, which implicitly pulls in 3rd party types and then magically switches to the ones provided by the package author when a package adds types.)
The documentation comment extraction system was also changed (following the system I’m using in CodeMirror 6) to use triple-slash comments for doc comments and get the types directly from TypeScript. The reference guide has already been updated to show the result of this.
Will prosemirror-tables be ported to a TypeScript project too in the future? It has some unfixed TS typing issues for a long time. (for example this one)
Whilst I acknowledge there are no breaking changes to the API - are there any plans to release this as a new major version, to minimise unforeseen impacts of changing type definitions?
Argument of type 'readonly Decoration[]' is not assignable to parameter of type 'Decoration[]'
This pattern is common when merging multiple decoration sets. Maybe we can allow DecorationSet.add (and also DecorationSet.remove, DecorationSet.create) to accept readonly Decoration[]?
Currently, a ProseMirror node variable will shown as Node$1 in VSCode, which is kind of confused. Would you think it’s possible to make it more meaningful, like Node or ProsemirrorNode?
Should PluginSpec be a generic type? Which is flowed through to the generic on StateField?
I think it would be helpful when defining a plugin, and ensuring your init and apply return new plugin state in the correct shape?
P.s. Would you prefer these questions raised as GitHub issues, on a per question basis? I wonder if it would be worth having a pinned issue there for all questions on the TypeScript annoucement?
domEventHandlers should now be smarter about the type of the event parameter.
This doesn’t help a lot, since it seems TypeScript is usually unable to infer the type of the type parameter, but can be useful when you explicitly declare it I guess. Added, with an any default type.