Skip to content

Instantly share code, notes, and snippets.

@holgergp
Created January 14, 2022 09:50
Show Gist options
  • Save holgergp/8852b97ee15e97f051f4d0596318b703 to your computer and use it in GitHub Desktop.
Save holgergp/8852b97ee15e97f051f4d0596318b703 to your computer and use it in GitHub Desktop.
Template String Types as Discriminants (TypeScript 4.5 Article)
export interface Success {
type: `${string}Success`;
body: string;
}
export function handler(r: Success | Error) {
if (r.type === "HttpSuccess") {
// (parameter) r: Success
const token = r.body;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment