Infer type guards from instanceof
and other such expressions
#21956
Labels
Duplicate
An existing issue was already created
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: