-
Notifications
You must be signed in to change notification settings - Fork 215
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
'make' namespace for kinds #10666
base: master
Are you sure you want to change the base?
'make' namespace for kinds #10666
Changes from all commits
05f23dd
ed3579d
16a2139
d77bb99
c1e4cea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,20 @@ | ||||||
/** | ||||||
* Takes an object of make* functions and returns an object with a single 'make' property | ||||||
* containing those functions renamed without the 'make' prefix. | ||||||
* | ||||||
* @template {Record<`make${string}`, Function>} T | ||||||
* @param {T} makers - Object containing make* functions | ||||||
* @returns {{ make: { [K in keyof T as K extends `make${infer R}` ? R : never]: T[K] } }} Transformed object | ||||||
*/ | ||||||
export const organizeMakers = makers => { | ||||||
const make = {}; | ||||||
for (const [key, fn] of Object.entries(makers)) { | ||||||
if (!key.startsWith('make')) { | ||||||
throw new Error(`Unexpected key ${key}`); | ||||||
} | ||||||
const newKey = key.slice(4); // Remove 'make' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
make[newKey] = fn; | ||||||
} | ||||||
// @ts-expect-error cast | ||||||
return harden({ make }); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why a record? why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To enforce that the name used is |
||||||
}; |
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 thought about a record like this, but sometimes you have to pass
makeA
intoprepareB
.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.
oh good point. That thought crossed my mind while I was refactoring but it consolidating like this was too delicious