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

未关闭
#57,032 20 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@jakebailey 已经在做这个了。

开始于 2024年1月16日。

评估

这个 Issue 还没有评估数据。

描述

In Discussion Suggestion
🔍 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
主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。