Skip to content

Instantly share code, notes, and snippets.

@magurotuna
Last active June 26, 2021 09:43
Show Gist options
  • Save magurotuna/a35b83de6e70c53b9d5322fc2d51addd to your computer and use it in GitHub Desktop.
Save magurotuna/a35b83de6e70c53b9d5322fc2d51addd to your computer and use it in GitHub Desktop.
// https://github.com/denoland/deno_doc/pull/105
export function f1(val1: A | B): val1 is A {}
export function f2(val2: any): asserts val2 is string {}
export function f3(val3: any): asserts val3 {}
export function assertIsDefined<T>(val4: T): asserts val4 is NonNullable<T> {
if (val === undefined || val === null) {
throw new AssertionError(
`Expected 'val' to be defined, but received ${val}`
);
}
}
export class C {
isSomething(): this is Something {
return this instanceof Something;
}
}
export type A = string | number;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment