GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Apply uncalled function checks to ternaries · Issue #36048 · microsoft/TypeScript

Apply uncalled function checks to ternaries #36048

New issue
Copy link
New issue
Copy link
Closed
#36402
Closed
Apply uncalled function checks to ternaries#36048
#36402
Copy link
Assignees
sandersn
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".SuggestionAn idea for TypeScriptAn idea for TypeScriptUpdate Docs on Next ReleaseIndicates that this PR affects docsIndicates that this PR affects docs
Milestone
TypeScript 3.9.0

Description

@ssalbdivad
David Blass (ssalbdivad)
opened on Jan 7, 2020
Issue body actions

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.
Reacted by SlurpTheo, Diego Stratta and Karol Majewski

Activity

  1. Ryan Cavanaugh (RyanCavanaugh)
    added
    Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancements
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    on Jan 7, 2020
  2. RyanCavanaugh commented on Jan 7, 2020

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Jan 7, 2020
    Member
    More actions

    Seems reasonable; we'd have to assess for breakage but I suspect this would turn out well

    Reacted by David Blass, Christopher Kiss and Titian Cernicova-Dragomir
  3. dragomirtitian commented on Jan 21, 2020

    @dragomirtitian
    Titian Cernicova-Dragomir (dragomirtitian)
    on Jan 21, 2020
    Contributor
    More actions

    Ryan Cavanaugh (@RyanCavanaugh) Are you taking PRs on this one?

    Reacted by Daniel Rosenwasser
  4. Daniel Rosenwasser (DanielRosenwasser)
    changed the title [-]Apply TS2774 to ternaries[/-] [+]Apply uncalled function checks to ternaries[/+] on Jan 21, 2020
  5. Daniel Rosenwasser (DanielRosenwasser)
    added
    Effort: 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 wanted
    on Jan 21, 2020
  6. DanielRosenwasser commented on Jan 21, 2020

    @DanielRosenwasser
    Daniel Rosenwasser (DanielRosenwasser)
    on Jan 21, 2020
    Member
    More actions

    Yes

    Reacted by Titian Cernicova-Dragomir and David Blass
  7. Daniel Rosenwasser (DanielRosenwasser)
    added this to the Backlog milestone on Jan 21, 2020
  8. Daniel Rosenwasser (DanielRosenwasser)
    added
    Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happens
    on Jan 21, 2020
  9. Daniel Rosenwasser (DanielRosenwasser)
    modified the milestones: Backlog, TypeScript 3.9.0 on Jan 28, 2020
  10. Daniel Rosenwasser (DanielRosenwasser)
    assigned
    Nathan Shively-Sanders (sandersn)
    on Jan 28, 2020
  11. DanielRosenwasser commented on Jan 28, 2020

    @DanielRosenwasser
    Daniel Rosenwasser (DanielRosenwasser)
    on Jan 28, 2020
    Member
    More actions

    Just assigning Nathan Shively-Sanders (@sandersn) so that we can follow up on the PR for 3.9 sooner rather than later.

  12. Daniel Rosenwasser (DanielRosenwasser)
    added
    Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing code
    on Feb 20, 2020
  13. Nathan Shively-Sanders (sandersn)
    closed this as completedin #36402on Feb 20, 2020
  14. Daniel Rosenwasser (DanielRosenwasser)
    added
    Update Docs on Next ReleaseIndicates that this PR affects docsIndicates that this PR affects docs
    and removed
    Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancements
    Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happens
    on Feb 20, 2020
  15. DanielRosenwasser commented on Feb 20, 2020

    @DanielRosenwasser
    Daniel Rosenwasser (DanielRosenwasser)
    on Feb 20, 2020
    Member
    More actions

    Thanks Oleksandr Tarasiuk (@a-tarasyuk)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sandersn
    Nathan Shively-Sanders (sandersn)

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".SuggestionAn idea for TypeScriptAn idea for TypeScriptUpdate Docs on Next ReleaseIndicates that this PR affects docsIndicates that this PR affects docs

Type

No type

Projects

No projects

    Milestone

    • TypeScript 3.9.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.