Skip to content

Commit 7375a0d

Browse files
committed
feat(types): simplify polymorphic type util
chore: update dev deps
1 parent 1cbeef2 commit 7375a0d

File tree

8 files changed

+699
-659
lines changed

8 files changed

+699
-659
lines changed

dev/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"@types/react": "19.0.8",
14-
"@types/react-dom": "19.0.3",
13+
"@types/react": "19.0.10",
14+
"@types/react-dom": "19.0.4",
1515
"@zayne-labs/toolkit": "workspace:*",
1616
"react": "19.0.0",
1717
"react-dom": "19.0.0"
@@ -20,8 +20,8 @@
2020
"@types/node": "^22.13.4",
2121
"@vitejs/plugin-react-swc": "^3.8.0",
2222
"@zayne-labs/tsconfig": "catalog:",
23-
"tsx": "^4.19.1",
23+
"tsx": "^4.19.3",
2424
"typescript": "5.7.3",
25-
"vite": "^6.1.0"
25+
"vite": "^6.1.1"
2626
}
2727
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"version-package": "changeset version"
2424
},
2525
"devDependencies": {
26-
"@changesets/cli": "^2.27.12",
27-
"@eslint-react/eslint-plugin": "^1.26.2",
26+
"@changesets/cli": "^2.28.1",
27+
"@eslint-react/eslint-plugin": "^1.27.0",
2828
"@types/node": "^22.13.4",
2929
"@zayne-labs/eslint-config": "^0.5.1",
3030
"@zayne-labs/tsconfig": "catalog:",

packages/toolkit-core/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@
4848
},
4949
"devDependencies": {
5050
"@arethetypeswrong/cli": "^0.17.3",
51-
"@changesets/cli": "^2.27.12",
52-
"@size-limit/esbuild-why": "^11.1.6",
53-
"@size-limit/preset-small-lib": "^11.1.6",
51+
"@changesets/cli": "^2.28.1",
52+
"@size-limit/esbuild-why": "^11.2.0",
53+
"@size-limit/preset-small-lib": "^11.2.0",
5454
"@total-typescript/ts-reset": "^0.6.1",
5555
"@types/node": "^22.13.4",
5656
"@zayne-labs/tsconfig": "catalog:",
5757
"clsx": "^2.1.1",
5858
"concurrently": "^9.1.2",
5959
"cross-env": "^7.0.3",
60-
"publint": "^0.3.5",
61-
"size-limit": "^11.1.6",
60+
"publint": "^0.3.6",
61+
"size-limit": "^11.2.0",
6262
"terser": "^5.39.0",
6363
"tsup": "^8.3.6",
6464
"typescript": "5.7.3"

packages/toolkit-react/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@
6767
},
6868
"devDependencies": {
6969
"@arethetypeswrong/cli": "^0.17.3",
70-
"@changesets/cli": "^2.27.12",
71-
"@size-limit/esbuild-why": "^11.1.6",
72-
"@size-limit/preset-small-lib": "^11.1.6",
70+
"@changesets/cli": "^2.28.1",
71+
"@size-limit/esbuild-why": "^11.2.0",
72+
"@size-limit/preset-small-lib": "^11.2.0",
7373
"@total-typescript/ts-reset": "^0.6.1",
7474
"@types/node": "^22.13.4",
75-
"@types/react": "^19.0.8",
76-
"@types/react-dom": "^19.0.3",
75+
"@types/react": "^19.0.10",
76+
"@types/react-dom": "^19.0.4",
7777
"@zayne-labs/tsconfig": "catalog:",
7878
"concurrently": "^9.1.2",
7979
"cross-env": "^7.0.3",
80-
"publint": "^0.3.5",
80+
"publint": "^0.3.6",
8181
"react": "^19.0.0",
8282
"react-dom": "^19.0.0",
83-
"size-limit": "^11.1.6",
83+
"size-limit": "^11.2.0",
8484
"terser": "^5.39.0",
8585
"tsup": "^8.3.6",
8686
"typescript": "5.7.3",
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
export type AsProp<TElement extends React.ElementType> = { as?: TElement };
1+
import type { Prettify } from "@zayne-labs/toolkit-type-helpers";
22

3-
// == Return the prop object if it already contains the "as" prop, else merge it with the "as" prop
4-
type PropsWithOptionalAs<TElement extends React.ElementType, TProps> = "as" extends keyof TProps
5-
? TProps
6-
: AsProp<TElement> & TProps;
3+
export type AsProp<TElement extends React.ElementType> = { as?: TElement };
74

8-
// == Get all other primitive element props by Omitting the result of MergedProps from React.ComponentPropsWithRef
9-
type InferOtherProps<TElement extends React.ElementType, TProps> = Omit<
5+
// == Get the rest of the primitive props by omitting the result of TProps from the ones gotten from React.ComponentPropsWithRef
6+
type InferRestOfProps<TElement extends React.ElementType, TProps> = Omit<
107
React.ComponentPropsWithRef<TElement>,
11-
keyof PropsWithOptionalAs<TElement, TProps>
8+
keyof TProps
129
>;
1310

11+
// prettier-ignore
12+
// == Merge the AsProp and the TProps, or omit the AsProp if the user passed their own
13+
type MergedPropsWithAs<TElement extends React.ElementType, TProps> = Omit<AsProp<TElement>, keyof TProps> & TProps;
14+
1415
// == Polymorphic props helper
1516
export type PolymorphicProps<
1617
TElement extends React.ElementType,
17-
// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is need so one can pass any prop without type errors
18-
TProps extends Record<keyof any, any> = AsProp<TElement>,
19-
> = InferOtherProps<TElement, TProps> & PropsWithOptionalAs<TElement, TProps>;
18+
// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is needed so one can pass any prop type without type errors
19+
TProps extends Record<keyof any, any>,
20+
> = InferRestOfProps<TElement, TProps> & Prettify<MergedPropsWithAs<TElement, TProps>>;

packages/toolkit-type-helpers/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545
},
4646
"devDependencies": {
4747
"@arethetypeswrong/cli": "^0.17.3",
48-
"@changesets/cli": "^2.27.12",
49-
"@size-limit/esbuild-why": "^11.1.6",
50-
"@size-limit/preset-small-lib": "^11.1.6",
48+
"@changesets/cli": "^2.28.1",
49+
"@size-limit/esbuild-why": "^11.2.0",
50+
"@size-limit/preset-small-lib": "^11.2.0",
5151
"@total-typescript/ts-reset": "^0.6.1",
5252
"@types/node": "^22.13.4",
5353
"@zayne-labs/tsconfig": "catalog:",
5454
"clsx": "^2.1.1",
5555
"concurrently": "^9.1.2",
5656
"cross-env": "^7.0.3",
57-
"publint": "^0.3.5",
58-
"size-limit": "^11.1.6",
57+
"publint": "^0.3.6",
58+
"size-limit": "^11.2.0",
5959
"terser": "^5.39.0",
6060
"tsup": "^8.3.6",
6161
"typescript": "5.7.3"

packages/toolkit/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
},
7171
"devDependencies": {
7272
"@arethetypeswrong/cli": "^0.17.3",
73-
"@changesets/cli": "^2.27.12",
73+
"@changesets/cli": "^2.28.1",
7474
"@total-typescript/ts-reset": "^0.6.1",
7575
"@types/node": "^22.13.4",
76-
"@types/react": "^19.0.8",
77-
"@types/react-dom": "^19.0.3",
76+
"@types/react": "^19.0.10",
77+
"@types/react-dom": "^19.0.4",
7878
"@zayne-labs/tsconfig": "catalog:",
7979
"concurrently": "^9.1.2",
8080
"cross-env": "^7.0.3",
81-
"publint": "^0.3.5",
81+
"publint": "^0.3.6",
8282
"react": "^19.0.0",
8383
"react-dom": "^19.0.0",
8484
"terser": "^5.39.0",

0 commit comments

Comments
 (0)