microsoft / microsoft/TypeScript

Support go-to-definition on tsconfig mapped paths for non-source files

Đang mở
#44,564 0 bình luận 6 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Experience Enhancement Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

Suggestion

The recent change in TypeScript 4.3 to bring go-to-definition support on non-JavaScript file paths is fantastic! I’d love to see this functionality extended to mapped paths defined in tsconfig.json.

🔍 Search Terms

  • go-to-definition (and “go to definition”)
  • paths
  • tsconfig

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

📃 Motivating Example

As of TypeScript 4.3,

import foo from "../styles/foo.css";

works well when using go-to-definition. This suggestion would make

import bar from "+styles/foo.css";

work just as well, opening up the underlying mapped file.

💻 Use Cases

This would be useful anywhere someone is using mapped paths in their tsconfig.json to shorten relative imports to commonly used directories (like a “styles” directory).

Here’s an example of how I imagine this working:

ts-gotodefs-example
├── package.json
├── src
│   ├── css.d.ts
│   └── index.ts
├── styles
│   └── foo.css
├── tsconfig.json

src/index.ts

// go-to-definition works, foo.css opens as of TS 4.3
import foo from "../styles/foo.css";
// this should also open foo.css but as of TS 4.3 it does not
import bar from "+styles/foo.css";

src/css.d.ts

declare module "*.css" {
    const classes: { [key: string]: string };
    export default classes;
}

tsconfig.json

{
    "compilerOptions": {
        "rootDir": "src",
        "outDir": "lib",
        "paths": {
            "+styles/*": ["./styles/*"]
        }
    }
}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với ví dụ trong src/index.ts và ánh xạ paths trong tsconfig.json của nó, sử dụng khai báo css.d.ts và đích styles/foo.css để tái hiện hành vi hiện tại. Hoàn tất khi go-to-definition phân giải +styles/foo.css thành tệp được ánh xạ, giống như với ../styles/foo.css.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
devtools
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.