* 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
40 lines
786 B
Plaintext
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
|
|
}
|
|
}
|
|
|