microsoft / microsoft/TypeScript

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

Ouverte
#34,539 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Awaiting More Feedback Domain: LS: Quick Fixes Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

L’issue décrit le comportement existant de tsserver pour l’auto-import et la complétion ; commencez par suivre la façon dont il identifie les symboles exportés. Le travail est terminé lorsque la complétion peut proposer un symbole global non exporté et que la sélection met à jour à la fois le module qui le définit avec un export et le module qui l’importe avec un import, tout en préservant le comportement existant.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, typescript
Domaine
developer-experience, tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.