Skip to content

Commit 5f5230d

Browse files
committed
fix(test): add proper type annotations to fix TypeScript errors
Add NetlifyContext and Env types for Hono instances that access c.env.context, resolving TS18046 'c.env is of type unknown' errors.
1 parent 40674cb commit 5f5230d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/adapter/netlify/handler.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import { Hono } from '../../hono'
22
import { handle } from './handler'
33

4+
type NetlifyContext = {
5+
geo: {
6+
city: string
7+
country: { code: string; name: string }
8+
}
9+
ip: string
10+
requestId: string
11+
}
12+
13+
type Env = {
14+
Bindings: {
15+
context: NetlifyContext
16+
}
17+
}
18+
419
describe('Netlify Adapter', () => {
520
// Mock Netlify context
6-
const createMockContext = (overrides = {}) => ({
21+
const createMockContext = (overrides = {}): NetlifyContext => ({
722
geo: {
823
city: 'San Francisco',
924
country: { code: 'US', name: 'United States' },
@@ -88,7 +103,7 @@ describe('Netlify Adapter', () => {
88103

89104
describe('Context Handling', () => {
90105
it('Should pass Netlify context to Hono env', async () => {
91-
const app = new Hono()
106+
const app = new Hono<Env>()
92107
app.get('/', (c) => {
93108
const netlifyCtx = c.env.context
94109
return c.json({
@@ -111,7 +126,7 @@ describe('Netlify Adapter', () => {
111126
})
112127

113128
it('Should access geo information from context', async () => {
114-
const app = new Hono()
129+
const app = new Hono<Env>()
115130
app.get('/geo', (c) => {
116131
const { geo } = c.env.context
117132
return c.json({

0 commit comments

Comments
 (0)