-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Go to definition for TypeScript literal strings #49033
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
Comments
Cc @RyanCavanaugh is there a way to put bug bounties on issues in order to incentivize OSS-contributors to take on tasks ahead of the core team? I'd happily put forward a few hundred $ personally for this to be solved as it's a big pain point in my API design of tRPC |
Interesting question; we do not currently have a mechanism for that. Other projects have had people put up bounties on third-party sites, e.g. dotnet/runtime#36748 (comment) . I was actually just on an internal email thread about this and the general consensus was that we're OK with good-faith bounties being staked, but want to "stay neutral" in terms of e.g. deciding which of two contributors should be awarded a bounty if both put up a PR. |
This comment was marked as outdated.
This comment was marked as outdated.
I'll throw in another $500 on this bounty @KATT |
@Andarist and I chatted a bit about this one. We suspect it's not straightforward or trivial to implement, but hopefully doable in our time budgets. Edit: @RyanCavanaugh responded immediately after this long text with answer ( Prior Debugging NotesWe'd both separately done similar investigations. Take my rough notes with a grain of salt because I'm not on the TypeScript team and don't know anything for sure:
Backing context:
Potential Implementation DirectionsWe discussed these three, in increasing order of likelihood to succeed:
Create new symbols for the literalsIs it possible that we could have more rich symbols per literal? Maybe yes, but that'd be a pretty big breaking change in how TypeScript and its consumers understand symbols. I'm under the impression many consumers -such as typescript-eslint- assume one symbol-per-literal, not one-symbol-per-literal-and-type. 👎 See what type the parent location isIs there a compiler API for "given a node, tell me what type it's expected to be"? E.g. if you're looking at a function argument, determining the intended type of the parameter? Neither of us could find one. If one exists: yes please, that would be an ideal solution! If not: ah well. Augment node links
Again: don't take these notes too seriously; we might be totally off in our direction. But either way: progress! 🚀 |
This is |
I'm not even sure how this can be made to work in practice. Let's consider something like const obj1 = {
hello: 1
};
const obj2 = {
foo: 0,
hello: 1,
baz: 2
};
declare let a: (keyof typeof obj1) & (keyof typeof obj2);
a = "hello"; // <- Here, |
So this is interesting. Yes, In fact, literal values and operator-computed values such as
Is it intentional that the type doesn't have a symbol? Could we add one in as part of this change?
I would think the Go to definition would be on the type annotation in full: |
That matches my thinking too. As to |
Yes. Literal types and unions don't have symbols because there's not an originating declaration for them; both are interned. |
Sorry to dig, but what does "interned" mean here? |
GitHub has changed Ctrl-Enter to "Close" and I am furious 👿 Edit: Oh thank god https://twitter.com/mariorod1/status/1542189296240713730 |
…with "static" generics) like: type B = { foo: 5, bar } const a = <T extends keyof B>(a: T) => {} a('foo')
Feature request
Go to definition for TypeScript literal strings.
Example
Given the below code, I would really like to be able to jump to the definition of the
'foo'
:Link to TypeScript playground.
WebStorm Demo of the same code
In WebStorm, it actually works how I wish that VSCode worked, here's a video:
nice.webstorm.mov
The text was updated successfully, but these errors were encountered: