diff --git a/src/validator/validator.test.ts b/src/validator/validator.test.ts index 493032e4fd..c56e48cabe 100644 --- a/src/validator/validator.test.ts +++ b/src/validator/validator.test.ts @@ -1368,3 +1368,34 @@ describe('Raw Request cloning after validation', () => { expect(result.payload).toMatchObject(testData) }) }) + +describe('Type inference in a validation function', () => { + type ExtractEnvFromContext = C extends Context ? E : never + type ExtractPathFromContext = C extends Context ? P : never + + const app = new Hono<{ + Variables: { + foo: string + } + }>() + + it('Should not throw type errors for the context', () => { + app.post( + '/user/:name', + validator('json', (_data, c) => { + type P = ExtractPathFromContext + type verify = Expect> + type E = ExtractEnvFromContext + type verify2 = Expect> + return {} + }), + (c) => { + type P = ExtractPathFromContext + type verify = Expect> + type E = ExtractEnvFromContext + type verify2 = Expect> + return c.json({}) + } + ) + }) +})