Skip to content
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

feat(typescript-estree): computed members discriminated unions #1349

Merged
merged 7 commits into from Dec 19, 2019

Commits on Dec 19, 2019

  1. chore: use discriminated unions for member name types

    property names are either `computed: false` with `key: Identifier | StringLiteral | NumberLiteral`, or they are `computed: true` with `key: Expression`.
    the previous typings took the simple approach of just having a single type, but it made things a bit more cumbersome.
    
    This change creates two types for each, using the `computed` value as the key for a discriminated union.
    This means that if you check `node.computed === true`, then TS will narrow the `key` type appropriately.
    
    I also noticed a minor bug in the `TSEnumMember` handling, as the types didn't previously support the fact that it's syntactically valid to use an expression (note it's semantically invalid - TS error 1164).
    It's also semantically and syntactically valid to do something like `enum Foo { ['key'] }`, which really should be handled differently to `enum Foo { key }`, even if they mean the same thing.
    So I also added a `computed` prop to `TSEnumMember`, and gave it the same discriminated union treatment.
    bradzacher committed Dec 19, 2019
    Configuration menu
    Copy the full SHA
    1a3d44b View commit details
    Browse the repository at this point in the history
  2. test: fix alignment tests

    bradzacher committed Dec 19, 2019
    Configuration menu
    Copy the full SHA
    0da7542 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    bc68644 View commit details
    Browse the repository at this point in the history
  4. test: update parser snaps

    bradzacher committed Dec 19, 2019
    Configuration menu
    Copy the full SHA
    3a8d6db View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    e91a7fe View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    1676146 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e732a12 View commit details
    Browse the repository at this point in the history