This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from web3well/cells-formula-rename
Use prefixKeys to avoid shadowing
- Loading branch information
Showing
8 changed files
with
45 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type RemovePrefix< | ||
Prefix extends string, | ||
T extends string, | ||
> = T extends `${Prefix}${infer AfterPrefix}` ? AfterPrefix : never; | ||
|
||
export type PrefixKeys< | ||
Prefix extends string, | ||
Obj extends Record<string, unknown>, | ||
> = { | ||
[K in `${Prefix}${keyof Obj & string}`]: Obj[RemovePrefix<Prefix, K>]; | ||
}; | ||
|
||
export default function prefixKeys< | ||
Prefix extends string, | ||
Obj extends Record<string, unknown>, | ||
>(prefix: Prefix, obj: Obj): PrefixKeys<Prefix, Obj> { | ||
return Object.fromEntries( | ||
Object.entries(obj).map(([k, v]) => [`${prefix}${k}`, v]), | ||
) as PrefixKeys<Prefix, Obj>; | ||
} |