Microsoft/TypeScript

Go to definition for TypeScript literal strings

Open

#49,033 建立於 2022年5月9日

在 GitHub 查看
 (14 留言) (78 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: LS: Symbol NavigationExperience EnhancementHelp WantedSuggestion

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

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':

const obj = {
  foo: 'bar' as const,
  hello: 'world' as const,
}

function get<T, K extends keyof T>(obj: T, path: K): T[K] {
  return obj[path]
}

const val = get(obj, 'foo')
//                   👆👆👆 Is there a way of make jump to definition work here?
//                         I really want to CMD+click `'foo'` and jump to line #2

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:

https://user-images.githubusercontent.com/459267/167470744-80bdd8af-b7fa-444a-84d5-7e3f83e7e003.mov

貢獻者指南