-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScriptUpdate Docs on Next ReleaseIndicates that this PR affects docsIndicates that this PR affects docs
Milestone
Description
Search Terms
ts2774 ternary condition error function called uncalled
Suggestion
TS2774 (implemented in #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.
Examples
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
Checklist
My suggestion meets these guidelines:
- [✔️] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [✔️] This wouldn't change the runtime behavior of existing JavaScript code
- [✔️] This could be implemented without emitting different JS based on the types of the expressions
- [✔️] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- [✔️] This feature would agree with the rest of TypeScript's Design Goals.
SlurpTheo, dbstratta and karol-majewski
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScriptUpdate Docs on Next ReleaseIndicates that this PR affects docsIndicates that this PR affects docs