microsoft / microsoft/TypeScript

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

Offen
#44,564 0 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Experience Enhancement Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Beispiel in src/index.ts und dem paths-Mapping in dessen tsconfig.json; verwende die css.d.ts-Deklaration und das Ziel styles/foo.css, um das aktuelle Verhalten zu reproduzieren. Als erledigt gilt, wenn go-to-definition +styles/foo.css in die zugeordnete Datei aufgelöst wird, genau wie bei ../styles/foo.css.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.