-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
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
Infer type guards from instanceof
and other such expressions
#21956
Comments
One of many duplicates of #5101. Did you try to search for related issues before posting this? |
I tried. My search foo is clearly lacking. |
Sure. I only ask because the issue posting template asks you to list what search terms you used... well, I guess it says that specifically for bug reports as opposed to suggestions. I have this fantasy that one day we will find the magic wording that eliminates duplicate issues while still encouraging legitimate bug reports and suggestions. But sadly it is only a dream. |
@jcalz sophisticated lexical analysis should be employed by GitHub searches :) |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Consider the following from here:
The type of
allAs
is(A | B)[]
where it would be more accurately typed asA[]
. If a type-guard was used,then the type would be
A[]
as expected.Getting the correct type from
filter
requires using the verbose formfilter(isA)
instead of the more terse formfilter(v => v instanceof A)
.Suggestion
Infer a guard from lambdas that imply a type narrowing if used in an
if
statement.For example,
would infer
a
to be of type(v: any) => v is Class
.would infer
b
to be type(v: any) => v is string
;This would allow useful typing of:
The text was updated successfully, but these errors were encountered: