Skip to content

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

Open
@timocov

Description

@timocov

πŸ” 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 timocov/dts-bundle-generator#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

Metadata

Metadata

Assignees

Labels

In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions