Skip to content

Commit

Permalink
docs: update union to object conversion example and TS playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Beraliv committed Dec 26, 2024
1 parent 19821e3 commit 52bbeed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/utils/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,24 @@ export const map: Record<InputType, Record<InputType, MapConfig>> = {
? Intersection
: never;
type Metadata = {pageUrl: string} | {videoId: string};
type LogMetadata = {
openBlogPage: {pageUrl: string};
loadVideo: {videoId: string};
};
type AllMetadata = UnionToIntersection<Metadata>;
type AllLogMetadata = UnionToIntersection<LogMetadata[keyof LogMetadata]>;
// ^? {pageUrl: string} & {videoId: string}
type LogFunction = UnionToIntersection<
{ [Action in keyof LogMetadata]: (action: Action, metadata: LogMetadata[Action]) => void }[keyof LogMetadata]
>;
declare const log: LogFunction;
log('openBlogPage', {pageUrl: 'https://www.typescriptlang.org/docs/handbook/2/basic-types.html'});
log('loadVideo', {videoId: 'KFWJGVDYZaw'});
`,
playgroundUrl: "https://tsplay.dev/WzV3eW",
playgroundUrl: "https://tsplay.dev/W41zXw",
applications: [
{
library: "ts-pattern",
Expand Down

0 comments on commit 52bbeed

Please sign in to comment.