TypeScript/tests/baselines/reference/truthinessCallExpressionCoercion3.types
Nathan Shively-Sanders 5deb676b3a
No did-you-mean-to-call error on casts Part 2 (#42779)
* No did-you-mean-to-call error on casts

I chose to do the ad-hoc check rather than yet another tree walk.

1. It's faster to run and easier to read.
2. This error came from looking at real code. It happened twice, so I
think the best estimate for other uses that happened zero times is in
fact zero.
3. I couldn't think of other places to put the cast, given the
restrictions on `testedNode` just before the new code.

* Skip parentheses
2021-02-12 10:07:59 -08:00

40 lines
786 B
Plaintext

=== tests/cases/compiler/truthinessCallExpressionCoercion3.ts ===
// from #41640, based on an example in ant-design
interface I {
always(): void
>always : () => void
}
function f(result: unknown) {
>f : (result: unknown) => unknown
>result : unknown
if ((result as I).always) {
>(result as I).always : () => void
>(result as I) : I
>result as I : I
>result : unknown
>always : () => void
return result
>result : unknown
}
}
function g(result: unknown) {
>g : (result: unknown) => unknown
>result : unknown
if (((result as I)).always) {
>((result as I)).always : () => void
>((result as I)) : I
>(result as I) : I
>result as I : I
>result : unknown
>always : () => void
return result
>result : unknown
}
}