microsoft / microsoft/TypeScript

Go to definition for class members hidden with Symbols takes to symbol itself

Open
#35,406 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

As a developer working with Custom Elements classes that have their class members available in runtime, I would like to use Symbol to hide internal methods and properties from the public API.

The drawback of this approach is that "go to definition" currently does not recognise the case when Symbol is used for a method, and jumps to the place where the Symbol itself is defined.

I'm not sure whether this is a bug or feature.

TypeScript Version: 3.8.0-dev.20191126

Search Terms: Go to definition, ECMAScript Symbols, Symbol

Code

const method = Symbol('method');

class Parent {
    protected [method]() {
        return 'parent';
    }
}

class Child extends Parent {
    protected [method]() {
        return super[method]() + ' child';
    }
}

Expected behavior:

When clicking on super[method], it should be possible to go to the line 4.

Actual behavior:

When clicking on super[method], go to definition moves to the line 1.

Playground Link: https://www.typescriptlang.org/play/?ts=3.8.0-dev.20191126&ssl=1&ssc=1&pln=38&pc=2#code/MYewdgzgLgBAtgUygCxAExgXhgZQJ5wBGIANgBQDkiK6FAlANwBQTwJAhhBDAArsBOCMLADeTGBJgAHfiCgJg8jAG1qqNAF0ydGGMn6YgqAFd+YGBSkChUCs30BfJk9YcuMAMLIAliQwIAD3kwNG4+QWFdcUkZOQUlGFUkdS0dPQMJI1NzCGMpBH4kmk1tGABqCxhgHz87aIknJyA

Related Issues:

I didn't found any related issue but the approach with using ES2015 Symbols was suggested to be used as a workaround for protected methods in mixins at https://github.com/microsoft/TypeScript/issues/17744#issuecomment-431534647

Contributor guide

Open the contributing guide

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 with the linked TypeScript playground and reproduce go-to-definition on super[method] in the provided Parent and Child classes. Trace the language-service entry point for computed symbol members; done means navigation reaches the Parent method on line 4 instead of the Symbol declaration on line 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.