Skip to content

Commit bc6386e

Browse files
Bump template and adjust docs on typegen (#12237)
* Bump template to v5 and update typegen * Update type safety docs
1 parent 9fb98fe commit bc6386e

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

docs/explanation/type-safety.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Type safety
44

55
# Type safety
66

7+
<docs-info>
8+
If you haven't done so already, check out our guide for <a href="../framework/how-to/setting-up-type-safety">setting up type safety</a> in a new project.
9+
</docs-info>
10+
711
React Router generates types for each route in your app that you can use to get type safety for each route module export.
812

913
For example, let's say you have a `products/:id` route configured:
@@ -37,8 +41,6 @@ export default function Component({
3741
}
3842
```
3943

40-
If you haven't done so already, check out our guide for [setting up type safety][setting-up-type-safety] in a new project.
41-
4244
## `typegen` command
4345

4446
You can manually generate types with the `typegen` command:

docs/framework/how-to/setting-up-type-safety.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
title: Setting up type safety
33
---
44

5-
To know more about how type safety works in React Router, check out our [dedicated explanation](../../explanation/type-safety).
6-
75
# Setting up type safety
86

7+
<docs-info>
8+
To learn more about how type safety works in React Router, check out our <a href="../../explanation/type-safety">dedicated explanation</a>.
9+
</docs-info>
10+
911
React Router generates types into a `.react-router/` directory at the root of your app.
1012
This directory is fully managed by React Router and is derived from your route config (`app/routes.ts` by default), so it should be gitignore'd.
1113

@@ -93,3 +95,27 @@ For monorepos, you can create this file in the repo root and use the [`cwd` opti
9395
</docs-info>
9496

9597
Now, VSCode will automatically run the `typegen:watch` script in a dedicated terminal anytime you open your project.
98+
99+
## Automatic typegen in your `dev` script (optional)
100+
101+
You can also adjust your `dev` script to automatically run type generation when you start your development server.
102+
103+
👉 **Install `npm-run-all` (or a similar tool to run multiple scripts in parallel)**
104+
105+
```shellscript nonumber
106+
npm i -D npm-run-all
107+
```
108+
109+
👉 **Add `dev:typegen` to your `dev` script**
110+
111+
```json
112+
{
113+
"scripts": {
114+
"dev": "run-p dev:*",
115+
"dev:react-router": "react-router dev",
116+
"dev:typegen": "react-router typegen --watch"
117+
}
118+
}
119+
```
120+
121+
Now when you run `npm run dev`, it will automatically run type generation in watch mode.

templates/basic/.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

templates/basic/.vscode/tasks.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "2.0.0",
3+
// This task is used to autogenerate type for React Router route modules
4+
// Feel free to remove it and use run `npm run typegen:watch` manually
5+
"tasks": [
6+
{
7+
"label": "React Router: Typegen",
8+
"type": "shell",
9+
"command": "npm run typegen:watch",
10+
"problemMatcher": [],
11+
"isBackground": true,
12+
"presentation": {
13+
"echo": true,
14+
"reveal": "always",
15+
"focus": false,
16+
"panel": "dedicated"
17+
},
18+
"runOptions": {
19+
"runOn": "folderOpen"
20+
}
21+
}
22+
]
23+
}

templates/basic/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
"dev": "react-router dev",
77
"build": "react-router build",
88
"start": "react-router-serve ./build/server/index.js",
9-
"typecheck": "react-router typegen && tsc"
9+
"typecheck": "react-router typegen && tsc",
10+
"typegen:watch": "react-router typegen --watch"
1011
},
1112
"dependencies": {
12-
"@react-router/node": "7.0.0-pre.4",
13-
"@react-router/serve": "7.0.0-pre.4",
13+
"@react-router/node": "7.0.0-pre.5",
14+
"@react-router/serve": "7.0.0-pre.5",
1415
"isbot": "^5.1.17",
1516
"react": "^18.3.1",
1617
"react-dom": "^18.3.1",
17-
"react-router": "7.0.0-pre.4"
18+
"react-router": "7.0.0-pre.5"
1819
},
1920
"devDependencies": {
20-
"@react-router/dev": "7.0.0-pre.4",
21+
"@react-router/dev": "7.0.0-pre.5",
2122
"@types/react": "^18.3.9",
2223
"@types/react-dom": "^18.3.0",
2324
"autoprefixer": "^10.4.20",

templates/basic/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"~/*": ["./app/*"]
2828
},
2929
"noEmit": true,
30-
"rootDirs": [".", "./.react-router/types"],
31-
"plugins": [{ "name": "@react-router/dev" }]
30+
"rootDirs": [".", "./.react-router/types"]
3231
}
3332
}

0 commit comments

Comments
 (0)