Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix middleware types with skipLibCheck: false #32025

Merged
merged 4 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/server/web/spec-extension/response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { I18NConfig } from '../../config-shared'
import type { CookieSerializeOptions } from 'next/dist/compiled/cookie'
import { NextURL } from '../next-url'
import { toNodeHeaders } from '../utils'
import cookie from 'next/dist/compiled/cookie'
import { CookieSerializeOptions } from '../types'

const INTERNALS = Symbol('internal response')
const REDIRECTS = new Set([301, 302, 303, 307, 308])
Expand Down
11 changes: 11 additions & 0 deletions packages/next/server/web/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ export interface NodeHeaders {
[header: string]: string | string[] | undefined
}

export interface CookieSerializeOptions {
domain?: string
encode?(val: string): string
expires?: Date
httpOnly?: boolean
maxAge?: number
path?: string
sameSite?: boolean | 'lax' | 'strict' | 'none'
secure?: boolean
}

export interface RequestData {
geo?: {
city?: string
Expand Down
16 changes: 0 additions & 16 deletions test/integration/middleware-typescript/test/index.test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const middleware: NextMiddleware = function (request) {
console.log(request.ua?.isBot)
console.log(request.ua?.ua)

return new Response(null, {
return new Response('hello from middleware', {
headers: {
'req-url-basepath': request.nextUrl.basePath,
'req-url-pathname': request.nextUrl.pathname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"skipLibCheck": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
Expand Down
33 changes: 33 additions & 0 deletions test/production/middleware-typescript/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-env jest */

import { join } from 'path'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'

const appDir = join(__dirname, '../app')

describe('should set-up next', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
pages: new FileRef(join(appDir, 'pages')),
'tsconfig.json': new FileRef(join(appDir, 'tsconfig.json')),
'next.config.js': new FileRef(join(appDir, 'next.config.js')),
},
dependencies: {
typescript: 'latest',
'@types/react': 'latest',
'@types/react-dom': 'latest',
},
})
})
afterAll(() => next.destroy())

it('should have built and started', async () => {
const html = await renderViaHTTP(next.url, '/interface/static')
expect(html).toContain('hello from middleware')
})
})