Skip to content

Commit 7bfcd20

Browse files
committed
initial commit
0 parents  commit 7bfcd20

17 files changed

+3808
-0
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist/

.prettierrc.cjs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
printWidth: 120,
4+
useTabs: true,
5+
singleQuote: true,
6+
endOfLine: 'auto',
7+
};

.vscode/settings.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"editor.formatOnSave": true,
6+
"editor.defaultFormatter": "esbenp.prettier-vscode",
7+
"[typescript]": {
8+
"typescript.preferences.importModuleSpecifier": "non-relative"
9+
},
10+
"[typescriptreact]": {
11+
"editor.codeActionsOnSave": {
12+
"source.organizeImports": true
13+
}
14+
},
15+
"window.commandCenter": true,
16+
"editor.rulers": [120],
17+
"workbench.tree.indent": 16
18+
}

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# React Router Typesafe
2+
3+
React Router Typesafe builds upon [react-router](https://github.com/remix-run/react-router) to add type-safety via the use of generics. It brings type functionality closer to Remix, the full-stack framework from the same authors.
4+
5+
## Contributing
6+
7+
Feel free to improve the code and submit a pull request. If you're not sure about something, create an issue first to discuss it.
8+
9+
## Patched utilities
10+
11+
| Status | Utility | Before | After |
12+
| ------ | -------------------- | ---------- | ----------------------------------------------------- |
13+
|| `defer` | `Response` | Generic matching the first argument |
14+
|| `useLoaderData` | `unknown` | Generic function with the type of the loader function |
15+
|| `useActionData` | `unknown` | Generic function with the type of the action function |
16+
| | `useRouteLoaderData` | `unknown` | |
17+
18+
## About
19+
20+
React Router is developed and maintained by [Remix Software](https://remix.run) and many [amazing contributors](https://github.com/remix-run/react-router/graphs/contributors).

eslintrc.cjs

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
module.exports = {
2+
extends: [
3+
'prettier',
4+
'@remix-run/eslint-config',
5+
'plugin:import/recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:import/typescript',
8+
],
9+
parser: '@typescript-eslint/parser',
10+
plugins: ['import', 'unused-imports', 'simple-import-sort', '@typescript-eslint'],
11+
12+
parserOptions: {
13+
ecmaVersion: 'latest',
14+
sourceType: 'module',
15+
project: true,
16+
tsconfigRootDir: __dirname,
17+
},
18+
settings: {
19+
'import/parsers': {
20+
'@typescript-eslint/parser': ['.ts', '.tsx'],
21+
},
22+
'import/resolver': {
23+
typescript: {
24+
project: ['tsconfig.json'],
25+
},
26+
node: {
27+
project: ['tsconfig.json'],
28+
},
29+
},
30+
},
31+
32+
rules: {
33+
/** No absolute imports */
34+
'import/no-absolute-path': 'error',
35+
36+
/** Ensures all imports appear before other statements */
37+
'import/first': ['error'],
38+
39+
/** Ensures there’s an empty line between imports and other statements */
40+
'import/newline-after-import': ['warn', { count: 1 }],
41+
42+
/** Sorts imports automatically */
43+
'simple-import-sort/imports': 'warn',
44+
45+
/** Ensures no unused imports are present, and only _ prefixed variables can be unused */
46+
'no-unused-vars': 'off',
47+
'unused-imports/no-unused-vars': [
48+
'warn',
49+
{
50+
vars: 'all',
51+
varsIgnorePattern: '^_',
52+
args: 'after-used',
53+
argsIgnorePattern: '^_',
54+
},
55+
],
56+
'unused-imports/no-unused-imports': 'error',
57+
'@typescript-eslint/no-misused-promises': 'off',
58+
59+
'no-restricted-syntax': [
60+
'warn',
61+
{
62+
selector: 'TSEnumDeclaration',
63+
message: 'Don’t declare enums! Use string literal unions instead, they’re safer and more ergonomic.',
64+
},
65+
],
66+
67+
'no-restricted-imports': [
68+
'error',
69+
{
70+
paths: [
71+
{
72+
name: 'react-router-dom',
73+
importNames: ['defer'],
74+
message: "Please import defer from '~/domains/routing/routing.utils' instead.",
75+
},
76+
{
77+
name: 'react-router-dom',
78+
importNames: ['useLoaderData'],
79+
message: "Please import useLoaderData from '~/domains/routing/routing.utils' instead.",
80+
},
81+
{
82+
name: 'react-router-dom',
83+
importNames: ['useActionData'],
84+
message: "Please import useActionData from '~/domains/routing/routing.utils' instead.",
85+
},
86+
],
87+
},
88+
],
89+
90+
'@typescript-eslint/no-unnecessary-condition': 'warn',
91+
'@typescript-eslint/no-unnecessary-type-arguments': 'warn',
92+
'@typescript-eslint/prefer-for-of': 'warn',
93+
'@typescript-eslint/prefer-function-type': 'warn',
94+
95+
/** Prefer types over interfaces */
96+
'@typescript-eslint/consistent-type-definitions': ['warn', 'type'],
97+
98+
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
99+
100+
/** Standardises arrays. Simple arrays use brackets, complex arrays uses generic syntax
101+
* @example - ❌ `const foo: Array<string> = [];`
102+
* @example - ✅ `const foo: string[] = [];`
103+
* @example - ❌ `const foo: ReturnType<typeof bar>[] = [];`
104+
* @example - ✅ `const foo: Array<ReturnType<typeof bar>> = [];`
105+
*/
106+
'@typescript-eslint/array-type': ['warn'],
107+
108+
/** Enforces generics on the cunstructor, not as type annotation.
109+
* @example - ❌ `const foo: Foo<string> = new Foo();`
110+
* @example - ✅ `const foo = new Foo<string>();`
111+
*/
112+
'@typescript-eslint/consistent-generic-constructors': ['warn', 'constructor'],
113+
114+
/** Prefer Record<X,Y> over {[key: X]: Y} syntax */
115+
'@typescript-eslint/consistent-indexed-object-style': ['warn', 'record'],
116+
117+
/** Already handled by unused-imports */
118+
'@typescript-eslint/no-unused-vars': 'off',
119+
120+
/** React uses that a lot */
121+
'@typescript-eslint/unbound-method': 'off',
122+
123+
'@typescript-eslint/ban-ts-comment': [
124+
'error',
125+
{
126+
'ts-expect-error': 'allow-with-description',
127+
'ts-ignore': true,
128+
'ts-nocheck': true,
129+
'ts-check': false,
130+
minimumDescriptionLength: 5,
131+
},
132+
],
133+
},
134+
};

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "react-router-typesafe",
3+
"version": "0.0.0",
4+
"description": "type safe patches of react-router-dom",
5+
"main": "./dist/index.js",
6+
"module": "./dist/index.mjs",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"require": "./dist/index.js",
11+
"import": "./dist/index.mjs",
12+
"types": "./dist/index.d.ts"
13+
}
14+
},
15+
"scripts": {
16+
"build": "tsup",
17+
"test": "vitest"
18+
},
19+
"keywords": [
20+
"react",
21+
"react-router",
22+
"react-router-dom",
23+
"remix",
24+
"remix-router"
25+
],
26+
"author": "fredericoo",
27+
"license": "ISC",
28+
"peerDependencies": {
29+
"react": ">= 17",
30+
"react-router-dom": ">= 6.4.0",
31+
"typescript": ">= 4.9"
32+
},
33+
"devDependencies": {
34+
"@changesets/cli": "^2.26.2",
35+
"eslint": "^8.45.0",
36+
"prettier": "^3.0.0",
37+
"tsup": "^7.1.0",
38+
"typescript": "^5.1.6",
39+
"vitest": "^0.33.0"
40+
}
41+
}

0 commit comments

Comments
 (0)