Skip to content
Myr

fix(type): degradation of generic type handling (#3138)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by m-shaka · committed by GitHub · parent 4d33e1c · Browse files · 3 files+25 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+25 added−2 removed

  • tests:+21 added−0 removed
  • other:+4 added−2 removed

3 files+25 added−2 removed

modified:src/utils/types.ts+3 added-1 removed
modified:src/context.ts+1 added-1 removed
178 unmodified lines
179 SimplifyDeepArray<T> extends JSONValue180 ? JSONValue extends SimplifyDeepArray<T>181 ? never182 : JSONParsed<T>183 : JSONParsed<T>,183 : never,184 U,185 'json'186 >187
621 unmodified lines
modified:src/types.test.ts+21 added
2246 unmodified lines
2247 }2248 type verify = Expect<Equal<Expected, Actual>>2249 })2250})2251describe('generic typed variables', () => {2252 type Variables = {2253 ok: <TData>(data: TData) => TypedResponse<{ data: TData }>2254 }2255 const app = new Hono<{ Variables: Variables }>()22562257 it('Should set and get variables with correct types', async () => {2258 const route = app2259 .use('*', async (c, next) => {2260 c.set('ok', (data) => c.json({ data }))2261 await next()2262 })2263 .get('/', (c) => {2264 const ok = c.get('ok')2265 return ok('Hello')2266 })2267 type Actual = ExtractSchema<typeof route>['/']['$get']['output']2268 type Expected = { data: string }2269 expectTypeOf<Actual>().toEqualTypeOf<Expected>()2270 })2271})