Skip to content
Myr

fix(client): show type error if `$get()` needs args (#937)

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

* fix(client): show type error if `$get()` needs args * denoify

authored by Yusuke Wada · committed by GitHub · parent 23a22e7 · Browse files · 9 files+60 added−21 removed
This commit

State

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

Diff stats

9 files+60 added−21 removed

  • tests:+24 added−1 removed
  • other:+36 added−20 removed

9 files+60 added−21 removed

modified:deno_dist/client/types.ts+10 added-2 removed
modified:deno_dist/utils/types.ts+6 added
modified:deno_dist/hono.ts+1 added-1 removed
18 unmodified lines
19 OnHandlerInterface,20 TypedResponse,21 MergePath,22 MergeSchemaPath,23 RemoveBlankRecord,23} from './types.ts'24import type { RemoveBlankRecord } from './utils/types.ts'25import { getPathFromURL, mergePath } from './utils/url.ts'2627type Methods = typeof METHODS[number] | typeof METHOD_NAME_ALL_LOWERCASE28
271 unmodified lines
modified:deno_dist/types.ts+1 added-7 removed
1 unmodified line
2/* eslint-disable @typescript-eslint/no-explicit-any */3/* eslint-disable @typescript-eslint/ban-types */4import type { Context } from './context.ts'5import type { Hono } from './hono.ts'6import type { UnionToIntersection } from './utils/types.ts'6import type { UnionToIntersection, RemoveBlankRecord } from './utils/types.ts'78////////////////////////////////////////9////// //////10////// Values //////
349 unmodified lines
360////// //////361////////////////////////////////////////362363export type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never364365export type RemoveBlankRecord<T> = T extends Record<infer K, unknown>366 ? K extends string367 ? T368 : never369 : never
modified:src/client/client.test.ts+24 added-1 removed
229 unmodified lines
230 expect(await res.text()).toMatch('Good Night')231 })232})233234describe('Infer the request type', () => {234describe('Infer the response/request type', () => {235 const app = new Hono()236 const route = app.get(237 '/',238 validator('query', () => {
33 unmodified lines
272 name: string273 }274 type verify = Expect<Equal<Expected, Actual['query']>>275 })276277 describe('Without input', () => {278 const route = app.get('/', (c) => c.jsonT({ ok: true }))279 type AppType = typeof route280281 it('Should infer response type the type correctly', () => {282 const client = hc<AppType>('/')283 const req = client.index.$get284285 type Actual = InferResponseType<typeof req>286 type Expected = { ok: boolean }287 type verify = Expect<Equal<Expected, Actual>>288 })289290 it('Should infer request type the type correctly', () => {291 const client = hc<AppType>('/')292 const req = client.index.$get293294 type Actual = InferRequestType<typeof req>295 type Expected = {}296 type verify = Expect<Equal<Expected, Actual>>297 })298 })299})300301describe('Merge path with `app.route()`', () => {302 const server = setupServer(
114 unmodified lines
modified:src/client/types.ts+10 added-2 removed
modified:src/utils/types.ts+6 added
9 unmodified lines
10) => void11 ? I12 : never1314export type RemoveBlankRecord<T> = T extends Record<infer K, unknown>15 ? K extends string16 ? T17 : never18 : never1920export type JSONPrimitive = string | boolean | number | null | undefined21export type JSONArray = (JSONPrimitive | JSONObject | JSONArray)[]22export type JSONObject = { [key: string]: JSONPrimitive | JSONArray | JSONObject }23export type JSONValue = JSONObject | JSONArray | JSONPrimitive
13 unmodified lines
modified:src/hono.ts+1 added-1 removed
18 unmodified lines
19 OnHandlerInterface,20 TypedResponse,21 MergePath,22 MergeSchemaPath,23 RemoveBlankRecord,23} from './types'24import type { RemoveBlankRecord } from './utils/types'25import { getPathFromURL, mergePath } from './utils/url'2627type Methods = typeof METHODS[number] | typeof METHOD_NAME_ALL_LOWERCASE28
271 unmodified lines
modified:src/types.ts+1 added-7 removed
1 unmodified line
2/* eslint-disable @typescript-eslint/no-explicit-any */3/* eslint-disable @typescript-eslint/ban-types */4import type { Context } from './context'5import type { Hono } from './hono'6import type { UnionToIntersection } from './utils/types'6import type { UnionToIntersection, RemoveBlankRecord } from './utils/types'78////////////////////////////////////////9////// //////10////// Values //////
349 unmodified lines
360////// //////361////////////////////////////////////////362363export type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never364365export type RemoveBlankRecord<T> = T extends Record<infer K, unknown>366 ? K extends string367 ? T368 : never369 : never