fix: explicitly add types to exports #576
Merged
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.
The types are exported and should be able to be used by library consumers. However, when these consumers use recommended TypeScript
moduleResolution
setting "node16" (https://www.typescriptlang.org/tsconfig#moduleResolution), that will force the resolution to follow what is declared in theexports
section ofpackage.json
-- where an explicit export of the types is currently missing.Note that this is different from the
types
field at the top-level ofpackage.json
, which is a legacy mechanism for the old module resolution (this comment explains it pretty well for a different project, which dropped support for the legacy approach: typescript-eslint/typescript-eslint#7186 (comment)).As wdi5 is released with dual packaging (commonjs + esm), and both version should support typescript, keeping the top-level types field around makes sense. This is also what the wdio-reporter plugin does: https://github.com/webdriverio/webdriverio/blob/d3e494d089d0545cf14ca88043d9599eaf98fa53/packages/wdio-reporter/package.json#L35
They even go a step further and have subpath exports combined with the conditional exports that wdi5 has at the moment (see https://nodejs.org/api/packages.html#subpath-exports and https://nodejs.org/api/packages.html#conditional-exports). Given that in my project, the conditional export only approach works fine, I have opted to not add the subpath variant as well in this PR.