microsoft / microsoft/TypeScript-TmLanguage

Tokenising failure on parenthesis-wrapped object literal's type assertion operators `as keyof typeof`

Open
#995 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
471
Forks
149
PR merge metrics
No merged PRs in 30d

Description

JavaScript and TypeScript Nightly version: 5.3.0-dev.20231015

Code

This is the minimal and possible code for compare and constrast.
The example might not cover all posibilities that leads to this issue.

type A = { a: "", b: "" }
const a = { a: "", b: "" }

const c = ({
    key: a.a, label: a.b[a.a as keyof typeof a.b]
})

const d = (
    {
        key: a.a, label: a.b[a.a as keyof typeof a.b]
    })

const e =
    { key: a.a, label: a.b[a.a as keyof typeof a.b] }

const f =
{
    key: a.a, label: a.b[a.a as keyof typeof a.b]
}

When the object literal is going to be written like d, the inner operator as keyof typeof is tokenised as variable.parameter.ts or (tsx), but not keyword.*.

image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the repository's TypeScript TextMate grammar files and reproduce the supplied examples in the relevant editor syntax highlighter. Compare the highlighting of as keyof typeof in the parenthesis-wrapped object literal with the other examples; done means those operators receive keyword scopes rather than variable.parameter.ts or the TSX equivalent.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.