We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The following code type checks:
class C { foo: number; } function foo (x : C | Array<C>) : C { if (x instanceof C) return x; return x[0]; }
However, if we add a type parameter to C, the following fails:
C
class C<A> { foo: A; } function foo<A> (x : C<A> | Array<C<A>>) : C<A> { if (x instanceof C) return x; return x[0]; }
There is an error on line 8 (return x;):
return x;
Type 'C<A> | C<A>[]' is not assignable to type 'C<A>'. Type 'C<A>[]' is not assignable to type 'C<A>'. Property 'foo' is missing in type 'C<A>[]'.
I've tried a couple of other things, but can't get this to type check. Is this a bug, or am I missing an obvious solution?
The text was updated successfully, but these errors were encountered:
looks like the same issue in #2388
Sorry, something went wrong.
No branches or pull requests
The following code type checks:
However, if we add a type parameter to
C
, the following fails:There is an error on line 8 (
return x;
):I've tried a couple of other things, but can't get this to type check. Is this a bug, or am I missing an obvious solution?
The text was updated successfully, but these errors were encountered: