Title: Apply uncalled function checks to ternaries · Issue #36048 · microsoft/TypeScript · GitHub
Open Graph Title: Apply uncalled function checks to ternaries · Issue #36048 · microsoft/TypeScript
X Title: Apply uncalled function checks to ternaries · Issue #36048 · microsoft/TypeScript
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?" erro...
Open Graph 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...
X 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 de...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36048
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Apply uncalled function checks to ternaries","articleBody":"## Search Terms\r\n\r\nts2774 ternary condition error function called uncalled\r\n\r\n## Suggestion\r\n\r\nTS2774 (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.\r\n\r\n## Examples\r\n\r\nNow:\r\n\r\n```ts\r\nconst isString = (value: unknown) =\u003e typeof value === \"string\"\r\n\r\n// Error (TS2774)\r\nif (isString) {\r\n}\r\n// No error\r\nisString ? true : false\r\n```\r\nIf this suggestion is adopted:\r\n\r\n```ts\r\nconst isString = (value: unknown) =\u003e typeof value === \"string\"\r\n\r\n// Error (TS2774)\r\nif (isString) {\r\n}\r\n// Error(TS2774)\r\nisString ? true : false\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [✔️] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [✔️] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [✔️] This could be implemented without emitting different JS based on the types of the expressions\r\n* [✔️] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [✔️] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n","author":{"url":"https://github.com/ssalbdivad","@type":"Person","name":"ssalbdivad"},"datePublished":"2020-01-07T02:13:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/36048/TypeScript/issues/36048"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:58f2f7be-519c-ead8-7137-be49075c1d48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D736:C7066:21576B:2CA15B:6964ED84 |
| html-safe-nonce | f474c67a06bdaf0d21541ac7342de4fb10d27e8bcae50cdc176c594e4037dd47 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzM2OkM3MDY2OjIxNTc2QjoyQ0ExNUI6Njk2NEVEODQiLCJ2aXNpdG9yX2lkIjoiNzM5MTQ5MzQ5Njc1MDAwOTczMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a1740a916714ee622d2c3d824a1f664fdd858b86938689dd87706d29fb35942f |
| hovercard-subject-tag | issue:546039091 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/36048/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c2674448fb99d7f1b60211003391528121f5b017ffd518b72bd64e207b72bc73/microsoft/TypeScript/issues/36048 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c2674448fb99d7f1b60211003391528121f5b017ffd518b72bd64e207b72bc73/microsoft/TypeScript/issues/36048 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ssalbdivad |
| hostname | github.com |
| expected-hostname | github.com |
| None | 53cd8ae9b65b7c4a0ad545ffeb3216839259a92733857ba426906c0655c5419d |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c140758368c0a01881f61b83770bd75cfe81e2c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width