microsoft / microsoft/TypeScript

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

Aperta
#44,564 0 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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/*"]
        }
    }
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l’esempio in src/index.ts e la mappatura di paths nel relativo tsconfig.json, usando la dichiarazione css.d.ts e il target styles/foo.css per riprodurre il comportamento attuale. Il lavoro è completato quando go-to-definition risolve +styles/foo.css nel file mappato, proprio come fa per ../styles/foo.css.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.