Created
November 10, 2021 14:50
-
-
Save kubarskii/cded2ebfc508779a879d794202c190b5 to your computer and use it in GitHub Desktop.
Opaque type using typescript
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
declare namespace Tag { | |
const OpaqueTagSymbol: unique symbol; | |
class OpaqueTag<S extends symbol> { | |
private [OpaqueTagSymbol]: S; | |
} | |
export type OpaqueType<T, S extends symbol> = T & OpaqueTag<S>; | |
} | |
export declare type Opaque<T, S extends symbol> = Tag.OpaqueType<T, S>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment