Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adamgen/95055b1957f9e851c2938c307f1d9e47 to your computer and use it in GitHub Desktop.
Save adamgen/95055b1957f9e851c2938c307f1d9e47 to your computer and use it in GitHub Desktop.
type a = 'aaa';
const b = 'a' + 'a' + 'a';
let c: a;
const IsA = (string: string): string is a => string === 'aaa';
c = b; // gives an error
if (IsA(b)) {
c = b; // is ok because of the type guard
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment