microsoft / microsoft/TypeScript

Expose `TypeChecker.getTypeOnlyAliasDeclaration` or similar API to detect if a symbol is a "value" or a "type"

Aperta
#57,032 20 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@jakebailey ci sta già lavorando.

Dal 16/1/2024.

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

Descrizione

🔍 Search Terms

"type checker", "getTypeOnlyAliasDeclaration", "detecting value vs type on a symbol"

✅ Viability Checklist
⭐ Suggestion

It would be nice if the compiler would expose TypeChecker.getTypeOnlyAliasDeclaration or similar function that would help to detect if a given symbol is a type or a value (e.g. a class is a type if it was imported/exported via import-type/export-type syntax.

📃 Motivating Example

I'm maintaining https://github.com/timocov/dts-bundle-generator and have the following issue https://github.com/timocov/dts-bundle-generator/issues/290. My problem is that I need to somehow detect if a module export symbol is a type or a value so I can detect whether the type of a symbol changes since its original declaration and its actual export so I can generate type export instead of exporting a value. I asked in the community discord and @jakebailey pointed that the type checker has function getTypeOnlyAliasDeclaration that might help. I've checked with my test cases and it seems it works like a charm. I understand that this function itself might not be what you actually want to expose from the API so I'm happy with either solution.

Also I'm happy to contribute for this feature.

💻 Use Cases
  1. What do you want to use this for? Use it in the tool dts-bundle-generator to address mentioned issue
  2. What shortcomings exist with current approaches? Nothing seems exist
  3. What workarounds are you using in the meantime? I can use the internal (not exposed) API for a while and hope it won't change in the future

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.