Fix typescript issues after latest release 7.1.0 #94
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.
With latest release 7.1.0, I had to install helmet as a dependency. This produced typescript errors (with all version of Helmet I tried):
koa-helmet/koa-helmet.d.ts
Line 11 in 884c4be
gives
This is fixed easily enough by importing
HelmetOptions
directly instead.But then we get another error:
That's happening because helmet removes
expectCt
and as a result this isn't available anymore. Helmet folks suggest to use the expect-ct package if needed, but I'm reluctant to add this as another peer-dependency if most users of koa-helmet don't need it.So instead I'm using a mapped type to construct koa-helmet's default export. This should adapt koa-helmet's type with whatever helmet version a project uses.
I'm also using the JS module syntax instead of the common module syntax.
I also had to fix new typescript issues in the test file that were surfaced after this change, which proves that the change is beneficial.
This is probably a breaking change and will need a major update, but given 7.1.0 should have been a major update too, I'd say it's OK.
Please tell me what you think!