-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
perf(types): define ParamKey
simply
#3837
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3837 +/- ##
========================================
Coverage 91.31% 91.31%
========================================
Files 161 161
Lines 10240 10240
Branches 2997 2897 -100
========================================
Hits 9351 9351
Misses 888 888
Partials 1 1 ☔ View full report in Codecov by Sentry. |
This comment has been minimized.
This comment has been minimized.
Bundle size check
Compiler Diagnostics
Reported by octocov |
The |
Can you review this too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked performance on Bun and found a 2x improvement.
runtime: bun 1.1.34 (x64-win32)
benchmark avg (min … max) p75 / p99 (min … top 1%)
------------------------------------------- -------------------------------
Before 632.50 µs/iter 634.60 µs █
(307.70 µs … 4.10 ms) 3.01 ms █
( 0.00 b … 2.30 gb) 88.40 mb ███▄▃▂▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁
After 345.72 µs/iter 340.70 µs █
(249.90 µs … 3.53 ms) 1.23 ms ▂█
( 0.00 b … 984.00 mb) 26.60 mb ██▇▄▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
Before
type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer Rest}`
? Rest extends `${infer _Pattern}?`
? `${Name}?`
: Name
: NameWithPattern;
type ParamKey<Component> = Component extends `:${infer NameWithPattern}`
? ParamKeyName<NameWithPattern>
: never;
export type TestCases = [
ParamKey<":user{id}">,
ParamKey<":post{id}">,
ParamKey<":comment{id}?">,
ParamKey<":user">,
ParamKey<":post">,
ParamKey<":comment">,
];
After
type ParamKey2<Component> = Component extends `:${infer NameWithPattern}`
? NameWithPattern extends `${infer Name}{${infer Rest}`
? Rest extends `${infer _Pattern}?`
? `${Name}?`
: Name
: NameWithPattern
: never;
export type TestCases2 = [
ParamKey2<":user{id}">,
ParamKey2<":post{id}">,
ParamKey2<":comment{id}?">,
ParamKey2<":user">,
ParamKey2<":post">,
ParamKey2<":comment">,
];
@EdamAme-x Thaaank! |
ParamKeyName
is unnecessary since it is used only inParamKey
. Removing it introduces decreasing inInstantiations
for TypeScript.The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code