Skip to content

Instantly share code, notes, and snippets.

@kubarskii
Created November 10, 2021 14:50
Show Gist options
  • Save kubarskii/cded2ebfc508779a879d794202c190b5 to your computer and use it in GitHub Desktop.
Save kubarskii/cded2ebfc508779a879d794202c190b5 to your computer and use it in GitHub Desktop.
Opaque type using typescript
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