ts2774 ternary condition error function called uncalled
TS2774 (implemented in https://github.com/microsoft/TypeScript/pull/32802), i.e. the "This condition will always return true since the function is always defined. Did you mean to call it instead?" error, provides a helpful hint for developers referencing a function in an if statement without calling it. However, the same check doesn't apply to ternaries, which is missing an opportunity to save some debug time and counterintuitive for devs who know about TS2774. I propose reusing TS2774 for developers who forget to call a function in a ternary.
Now:
const isString = (value: unknown) => typeof value === "string"
// Error (TS2774)
if (isString) {
}
// No error
isString ? true : false
If this suggestion is adopted:
const isString = (value: unknown) => typeof value === "string"
// Error (TS2774)
if (isString) {
}
// Error(TS2774)
isString ? true : false
My suggestion meets these guidelines:
Seems reasonable; we'd have to assess for breakage but I suspect this would turn out well
@RyanCavanaugh Are you taking PRs on this one?
Yes
Just assigning @sandersn so that we can follow up on the PR for 3.9 sooner rather than later.
Thanks @a-tarasyuk!
Most helpful comment
Seems reasonable; we'd have to assess for breakage but I suspect this would turn out well