microsoft / microsoft/TypeScript
API: add function to resolve global symbol
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Suggestion
🔍 Search Terms
symbol, constructor, well known, global
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Expose getGlobalSymbol on TypeChecker
📃 Motivating Example
TypeScript applies some special handling to global declarations, e.g. Array, Object, Function, ReadonlyArray,
The recent change to well known Symbols adds yet another special case for the global Symbol value symbol.
Currently there's no reliable way to obtain the symbol of a global declaration.
💻 Use Cases
To find out whether a type is iterable, I need to look for a __@iterable property. Previously that worked well with a hard coded string. Now I need to look up the global Symbol constructor type, get the type of its property iterator and use the escapedName for the lookup on the type in question. The first step is actually the tricky one, because there's no API for it.
There are a few workarounds I can think of:
- the hacky way:
checker.getSymbolsInScope('' as any, ts.SymbolFlags.Value).filter(s => s.escapedName === 'Symbol') - the not so obvious way:
- find a property whose name starts with
__@since those are symbol names - its
valueDeclarationmust be aNamedDeclarationwith aComputedPropertyName - get the type of the computed property name to obtain a reference to the
(unique) symboltype getApparentTypeto obtain a reference to the globalSymboltype- its
symbolshould hopefully always refer to the globalSymbolconstructor
- find a property whose name starts with
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
TypeChecker API と、issue で説明されている既存のグローバル宣言の特殊ケース(Array、Object、Function、ReadonlyArray、Symbol を含む)から始めます。公開の getGlobalSymbol エントリポイントが checker API にどのように適合するかを判断し、グローバル宣言の解決に関するカバレッジを追加します。完了の条件は、コンシューマーが列挙された workaround なしでグローバルな Symbol コンストラクターのシンボルを確実に取得できることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100