Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export opaque type ID: string = string;
- function validateID(x: string): ID | void {
- if ( /* some validity check passes */ ) {
- return x;
- }
- return undefined;
- }
- import type {ID} from './exports';
- function formatID(x: ID): string {
- return "ID: " + x; // Ok! IDs are strings.
- }
- function toID(x: string): ID {
- return x; // Error: strings are not IDs.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement