Skip to content

Emit issue with member access dot operator and parentheses usually in conjunction with type assertion #15444

Description

Code

a.foo()
(b).foo()

Expected emit:

a.foo();
(b).foo();

Actual emit:

a.foo()(b).foo();

This becomes an issue when using type assertions inline:

Code

a.foo()
(b as Bar).foo()

Expected emit:

a.foo();
b.foo();

Actual emit:

a.foo()(b).foo();

Angle brackets type assertion have a similar issue:

Code

a.foo()
<Bar>b.foo()

Actual emit:

a.foo()
    < Bar > b.foo();

Activity

  1. mhegazy commented on Apr 28, 2017

    @mhegazy
    Contributor

    Unfortunately these are the JavaScript Automatic SemiColon Insertion rules.

    TypeScript is a super-set of JavaScript, and the samples above are valid JS code samples, and they have valid semantics. the emitted code has to match these semantics.

  2. gdelmas commented on Apr 28, 2017

    @gdelmas
    Author

    thanks for your reply Mohamed Hegazy (@mhegazy). i thought that it is a tricky case, as sometimes a multiline expression might be intended.

    i might create a tslint warning to detect it in conjunction with assertions. or might this be a case where tsc can warn itself?

  3. RyanCavanaugh commented on Apr 28, 2017

    @RyanCavanaugh
    Member

    I believe there's already a TSLint rule for missing semicolons

  4. gdelmas commented on Apr 28, 2017

    @gdelmas
    Author

    do you mean this tslint core rule:

    "semicolon": [true, "never"]
    

    "never" disallows semicolons at the end of every statement except for when they are necessary.

    the rule does not warn if a semicolon in conjunction with a type assertion might be required. it also fails in some other cases, and warns. for example:

    super(); <-- rule thinks this is unnecessary
    (a as Bar).foo()
    
  5. RyanCavanaugh commented on Apr 28, 2017

    @RyanCavanaugh
    Member

    Sorry, I totally misread that. Disregard.

    Mohamed Hegazy (@mhegazy) perhaps we should disallow boolean as an operand to > / <, even if the other operand is any ?

  6. ajafff commented on Apr 28, 2017

    @ajafff
    Contributor

    Gerard Delmàs (@gdelmas) you can use the no-unexpected-multiline provided by tslint-eslint-rules

  7. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    Mohamed Hegazy (@mhegazy) perhaps we should disallow boolean as an operand to > / <, even if the other operand is any

    👍

  8. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    Filed #15506 to track it.

  9. mhegazy commented on May 19, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  10. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions