panva / jose

JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes.
MIT License
5.4k stars 309 forks source link

createLocalJWKSet should not generate a TS error when called with immutable input #634

Closed matthieusieben closed 7 months ago

matthieusieben commented 7 months ago

What happened?

The following:

createLocalJWKSet({ keys: [] as readonly string[] } as const)

Generated this error:

The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'JWK[]'.ts (4104)

Since the JWKS will be cloned by createLocalJWKSet, there should not be any issue with marking the input as readonly.

IMO this is important as freezing the jwks can prevent any alteration, making the code more consistent and safer.

Version

5.2.0

Runtime

Other (I will specify below)

Runtime Details

types

Code to reproduce

createLocalJWKSet({ keys: [] as readonly string[] } as const)

Required

matthieusieben commented 7 months ago

Note: same goes for:

panva commented 7 months ago

If you wish to make a non-breaking suggestion to the type definitions then by all means please submit a PR. I'm not seeing typing inconveniences as major issues though.