TypeScript/tests/baselines/reference/truthinessCallExpressionCoercion3.js
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

30 lines
530 B
TypeScript

//// [truthinessCallExpressionCoercion3.ts]
// from #41640, based on an example in ant-design
interface I {
always(): void
}
function f(result: unknown) {
if ((result as I).always) {
return result
}
}
function g(result: unknown) {
if (((result as I)).always) {
return result
}
}
//// [truthinessCallExpressionCoercion3.js]
function f(result) {
if (result.always) {
return result;
}
}
function g(result) {
if (result.always) {
return result;
}
}