microsoft / microsoft/TypeScript

Add quick fix to export unexported members to fix unresolved symbol errors

Offen
#34,539 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Domain: LS: Quick Fixes Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

import
export
unexported
symbols
auto import
completion
global
globals
intellisense

Suggestion

tsserver can auto-complete exported symbols from other modules, and add an import statement that imports the symbol you selected.

It should also suggest global symbols from other modules that are not exported, and add the export keyword if the suggestion is selected.

Use Cases

When I write a module I can't predict every use case of it, and I only export the global symbols that I think other modules would need to use. But when I'm working on a different module and I realize I want to use a symbol which is not exported by the other module (or maybe I don't even remember if it is or isn't exported), I would like my editor to export and import it for me instead of me having to find that symbol manually (because even go-to definition won't work) and export it, and then go back and auto-complete to auto-import.

This is also very very very useful when converting a web project to use imports. You can just go over all of the "undeclared symbol" errors and auto-complete to export and import the correct symbol.

Examples

module.ts:

function foo(name = 'World') {
  console.log('Hello ' + name);
}

export function bar() {
  foo();
}

app.ts:

import { bar } from './module.ts';

bar();

I now want to customize the "hello" message, so I start typing foo and then wait for completion suggestions which include the function foo from module.ts.

After selecting that, the symbol foo is automatically exported and imported for me, and I can use it immediately:

module.ts:

export function foo(name = 'World') {
  console.log('Hello ' + name);
}

export function bar() {
  foo();
}

app.ts:

import { bar, foo } from './module.ts';

bar();
foo('TypeScript');

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

Das Issue beschreibt das bestehende Verhalten von tsserver bei Auto-Import und Vervollständigung. Beginne damit nachzuverfolgen, wie exportierte Symbole identifiziert werden. Als erledigt gilt, wenn die Vervollständigung ein nicht exportiertes globales Symbol anbieten kann und die Auswahl sowohl das definierende Modul um einen Export als auch das importierende Modul um einen Import ergänzt, wobei das bestehende Verhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
developer-experience, tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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