Skip to content

Commit fef407d

Browse files
committed
Adds test for Generic return type with a typeguard function parameter
1 parent b548de8 commit fef407d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/cases/conformance/expressions/typeGuards/typeGuardFunction.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function isArrayOf_2<T>(of: (item) => item is T, a: any[]): a is T[] {
4141
return true;
4242
}
4343

44+
declare function getObjectOfType<T>(of: (item: any) => item is T, obj: any[]): T;
45+
4446
function foo(): Foo {
4547
return <Foo>a;
4648
}
@@ -133,6 +135,9 @@ if (isBaz(b)) {
133135
a.baz(); // Error
134136
}
135137

138+
// Error: Type Foo is not assignable to string
139+
var f: string = getObjectOfType(isFoo, [1, 2]);
140+
136141
// The parameter index and argument index for the type guard target is not matching.
137142
if (hasMultipleParameters(0, a)) {
138143
a.foo(); // Error

0 commit comments

Comments
 (0)