Skip to content

"optional" does not exist on computed optional class property with variable #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sosukesuzuki opened this issue Sep 29, 2019 · 2 comments · Fixed by #1026
Closed

"optional" does not exist on computed optional class property with variable #1019

sosukesuzuki opened this issue Sep 29, 2019 · 2 comments · Fixed by #1026
Labels
bug Something isn't working has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@sosukesuzuki
Copy link
Contributor

(This issue related on prettier/prettier#6569)

What code were you trying to parse?

// Put your code here
const bar = "bar";
class Foo {
    [bar]?;
}

What did you expect to happen?

{
  "type": "ClassProperty",
  "key": {
    "type": "Identifier",
    "name": "bar",
    "range": [36, 39],
    "loc": {
      "start": {
        "line": 4,
        "column": 5
      },
      "end": {
        "line": 4,
        "column": 8
      }
    }
  },
  "value": null,
  "computed": true,
  "static": false,
  "range": [35, 42],
  "loc": {
    "start": {
      "line": 4,
      "column": 4
    },
    "end": {
      "line": 4,
      "column": 11
    }
  },
  "optional": true // This "optional" should exist
}

What actually happened?

{
  "type": "ClassProperty",
  "key": {
    "type": "Identifier",
    "name": "bar",
    "range": [36, 39],
    "loc": {
      "start": {
        "line": 4,
        "column": 5
      },
      "end": {
        "line": 4,
        "column": 8
      }
    }
  },
  "value": null,
  "computed": true,
  "static": false,
  "range": [35, 42],
  "loc": {
    "start": {
      "line": 4,
      "column": 4
    },
    "end": {
      "line": 4,
      "column": 11
    }
  }
}

It works fine for computed optional properties that do not use variables.

class Foo {
  ["bar"]?;
  [1]?;
}

Versions

package version
@typescript-eslint/typescript-estree 2.3.1
TypeScript 3.4.1
node 12.10.0
npm 6.11.3
@sosukesuzuki sosukesuzuki added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look labels Sep 29, 2019
@sosukesuzuki sosukesuzuki changed the title "optional" does not exist on computed variable optional class property "optional" does not exist on computed optional class property with variable Sep 29, 2019
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this and removed triage Waiting for team members to take a look labels Sep 30, 2019
@bradzacher
Copy link
Member

who the heck is writing and wanting to use such an abomination?!?
What's the point of typescript if you're providing no types....

It's a simple enough fix.

@bradzacher
Copy link
Member

The fix will be released (automatically) some time this afternoon

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants