0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

fix(types): handle readonly array correctly (#3172)

This commit is contained in:
m-shaka 2024-07-22 11:22:11 +09:00 committed by GitHub
parent a285c4b3b4
commit bb14b1e5ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -101,6 +101,11 @@ describe('JSONParsed', () => {
type Expected = (number | null)[]
expectTypeOf<Actual>().toEqualTypeOf<Expected>()
})
it('should convert { key: readonly T[]} correctly', () => {
type Actual = JSONParsed<{ key: readonly number[] }>
type Expected = { key: readonly number[] }
expectTypeOf<Actual>().toEqualTypeOf<Expected>()
})
})
describe('tuple', () => {

View File

@ -56,6 +56,8 @@ export type JSONParsed<T> = T extends { toJSON(): infer J }
? [JSONParsed<InvalidToNull<R>>, ...JSONParsed<U>]
: T extends Array<infer U>
? Array<JSONParsed<InvalidToNull<U>>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<JSONParsed<InvalidToNull<U>>>
: T extends Set<unknown> | Map<unknown, unknown>
? {}
: T extends object