Repository: honojs/hono
File: src/hono.test.ts (TypeScript)

Code before:
    app.get('/', (c) => {
      const id = c.get('id')
      const title = c.get('title')
      // type verifyID = Expect<Equal<number, typeof id>>
      expectTypeOf(id).toEqualTypeOf<number>()
      // type verifyTitle = Expect<Equal<string, typeof title>>
      expectTypeOf(title).toEqualTypeOf<string>()
      return c.text(`${id} is ${title}`)
    })
    const res = await app.request('http://localhost/')
    expect(res.status).toBe(200)
    expect(await res.text()).toBe('123 is Hello')
  })
})

describe('Context binding variables', () => {
  type Bindings = {
    USER_ID: number
    USER_NAME: string
  }

  const app = new Hono<{ Bindings: Bindings }>()

  it('Should get binding variables with correct types', async () => {
    app.get('/', (c) => {
      expectTypeOf(c.env.USER_ID).toEqualTypeOf<number>()
      expectTypeOf(c.env.USER_NAME).toEqualTypeOf<string>()
      return c.text('These are verified')
    })
    const res = await app.request('http://localhost/')
    expect(res.status).toBe(200)
  })
})

describe('Handler as variables', () => {
  const app = new Hono()

  it('Should be typed correctly', async () => {
    const handler: Handler = (c) => {
      const id = c.req.param('id')
      return c.text(`Post id is ${id}`)
    }
    app.get('/posts/:id', handler)

    const res = await app.request('http://localhost/posts/123')
    expect(res.status).toBe(200)
    expect(await res.text()).toBe('Post id is 123')
  })
})

describe('Show routes', () => {

Review comment (suggestion):
It does not pass, though it seems to be correct. What do you think to write like the following instead of that as a workaround:

```ts
 expectTypeOf(c.env).toEqualTypeOf<Bindings>()
```

Code after:
    app.get('/', (c) => {
      const id = c.get('id')
      const title = c.get('title')
      // type verifyID = Expect<Equal<number, typeof id>>
      expectTypeOf(id).toEqualTypeOf<number>()
      // type verifyTitle = Expect<Equal<string, typeof title>>
      expectTypeOf(title).toEqualTypeOf<string>()
      return c.text(`${id} is ${title}`)
    })
    const res = await app.request('http://localhost/')
    expect(res.status).toBe(200)
    expect(await res.text()).toBe('123 is Hello')
  })
})

describe('Context binding variables', () => {
  type Bindings = {
    USER_ID: number
    USER_NAME: string
  }

  const app = new Hono<{ Bindings: Bindings }>()

  it('Should get binding variables with correct types', async () => {
    app.get('/', (c) => {
      expectTypeOf(c.env).toEqualTypeOf<Bindings>()
      return c.text('These are verified')
    })
    const res = await app.request('http://localhost/')
    expect(res.status).toBe(200)
  })
})

describe('Handler as variables', () => {
  const app = new Hono()

  it('Should be typed correctly', async () => {
    const handler: Handler = (c) => {
      const id = c.req.param('id')
      return c.text(`Post id is ${id}`)
    }
    app.get('/posts/:id', handler)

    const res = await app.request('http://localhost/posts/123')
    expect(res.status).toBe(200)
    expect(await res.text()).toBe('Post id is 123')
  })
})

describe('Show routes', () => {
  const app = new Hono()