mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What?
Expose the `MiddlewareConfig` interface.
### Why?
You can now `import type { MiddlewareConfig } from "next/server"` to
type the `config` object in your `middleware.ts` file.
Now you an type the entire file for example like so:
```ts
// middleware.ts
import type { NextMiddleware, MiddlewareConfig } from "next/server"
export const middleware: NextMiddleware = async (req) => {
//...
}
export const config: MiddlewareConfig = {
//...
}
```
### How?
Re-exported the interface from its current location via
`server/web/types`, to colocate it with `NextMidldeware`.
I wonder if we could somehow type this file automatically, but it might
be dependent on https://github.com/microsoft/TypeScript/issues/38511
Closes NEXT-2308
[Slack
thread](https://vercel.slack.com/archives/C03S9JCH2Q5/p1706287433026409?thread_ts=1706058855.423019&cid=C03S9JCH2Q5),
[Slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1706659724141899)
16 lines
862 B
TypeScript
16 lines
862 B
TypeScript
import type { AsyncLocalStorage as NodeAsyncLocalStorage } from 'async_hooks'
|
|
|
|
declare global {
|
|
var AsyncLocalStorage: typeof NodeAsyncLocalStorage
|
|
}
|
|
|
|
export { NextFetchEvent } from 'next/dist/server/web/spec-extension/fetch-event'
|
|
export { NextRequest } from 'next/dist/server/web/spec-extension/request'
|
|
export { NextResponse } from 'next/dist/server/web/spec-extension/response'
|
|
export { NextMiddleware, MiddlewareConfig } from 'next/dist/server/web/types'
|
|
export { userAgentFromString } from 'next/dist/server/web/spec-extension/user-agent'
|
|
export { userAgent } from 'next/dist/server/web/spec-extension/user-agent'
|
|
export { URLPattern } from 'next/dist/compiled/@edge-runtime/primitives/url'
|
|
export { ImageResponse } from 'next/dist/server/web/spec-extension/image-response'
|
|
export type { ImageResponseOptions } from 'next/dist/compiled/@vercel/og/types'
|