Skip to content

Commit

Permalink
Add stub Route type for typedRoutes (#48099)
Browse files Browse the repository at this point in the history
### What? Why? How?

Add a stub `Route` type to avoid TS errors with `typedRoutes: true`
before `next dev` and `next build` are run

Ref:
#47931 (comment)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Shu Ding <g@shud.in>
  • Loading branch information
karlhorky and shuding committed May 10, 2023
1 parent 6a3f96e commit 4743dc6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/next/types/index.d.ts
Expand Up @@ -37,6 +37,18 @@ export type {
ResolvingMetadata, // @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/lib/metadata/types/metadata-interface'

/**
* Stub route type for typedRoutes before `next dev` or `next build` is run
* @link https://beta.nextjs.org/docs/configuring/typescript#statically-typed-links
* @example
* ```ts
* import type { Route } from 'next'
* // ...
* router.push(returnToPath as Route)
* ```
*/
export type Route = string & {}

// Extend the React types with missing properties
declare module 'react' {
// <html amp=""> support
Expand Down

0 comments on commit 4743dc6

Please sign in to comment.