1interface Foo { bar(): void }
2declare function getFoo(): Foo | undefined;
3
4function assert(value: unknown): asserts value {
5 if (value === undefined) {
6 throw new Error('value must be defined');
7 }
8}
9
10function test() {
11 const foo = getFoo();
12 // foo is Foo | undefined here
13 assert(foo);
14 // foo narrowed to Foo
15 foo.bar();
16}
17