chores: various clean ups regardin ESM and TypeScript #2117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been spending a lot of time going through our types, reading through documentation, or some subjective best practices other developers have put together regarding how to define types.
I apply some of these here, plus a few other small chores.
Remove Main from
package.json
Packages that don't support Node.js versions below v12 don't need to define both. The
export
property supersedes themain
property, so the old property can be dropped entirely.We would only need to preserve
main
if we're expected users to pull it in to Node.js v12, but our minimum supported version is Node.js v16.The primary difference between the two is that when using
main
, it exports all files in the package for public use. Whileexports
enables us to define our public API, so that developers are less likely to depend on our internal API in their projects.By defining a clear boundary between public and private API, users are less likely to encounter situations where a non-breaking change is breaking for them, because they depended on internal code.
Upgrade Types
Ideally, the
@types/
package versions would match themajor
andminor
version of the implementation library. This upgrades them to either match or at least be as close as possible.DefinitelyTyped make the
major
andminor
version match the implementation version, then thepatch
version is less relevant. This ensures we're linting against the correct types.Move comment to
@fileoverview
I prefer when important information are maintained in JSDocs rather than comments. This one seemed fine to move to a JSDoc.
Prefer
ReadonlyArray<>
over[]
for@params
This one I'm taking from the guidance for DefinitelyTyped. While we don't have to follow the same rules, I think it'd be nice to adhere to similar rules, and I see no harm in applying this change.
This can actually be better as before, while users could pass regular arrays to these functions, they could not pass readonly arrays. Now, a user can pass both to functions where we weren't modifying the array anyway.