generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e98b27
commit 75c57bb
Showing
3 changed files
with
74 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
export interface Tagged { readonly tag: string } | ||
export type Tag<T extends Tagged> = { readonly tag: T['tag'] } | ||
|
||
// build a tag value for an Tagged type, | ||
export interface Tagged { | ||
readonly tag: string | ||
} | ||
|
||
const tagKey: unique symbol = Symbol() | ||
|
||
export type Tag<T extends Tagged> = { | ||
readonly [tagKey]: T['tag'] | ||
} | ||
|
||
// build a tag value for a Tagged type, | ||
// forcing the tag param to match the Tagged.tag string | ||
// const aTag = tag<ATagged>("ATagged") | ||
export const tag = <T extends Tagged>(tag: T['tag']): Tag<T> => { return { tag } } | ||
export const tag = <T extends Tagged>(tag: T['tag']): Tag<T> => { | ||
return { | ||
[tagKey]: tag | ||
} | ||
} | ||
|
||
// get the tag string from a Tag | ||
export const tagStr = <T extends Tagged>(tag: Tag<T>): Tag<T>[typeof tagKey] => { | ||
return tag[tagKey] | ||
} |