microsoft / microsoft/TypeScript

[API] Ability to check if a parameter is being passed to const type parameter

オープン
#58,656 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔍 Search Terms

const type parameter

✅ Viability Checklist
⭐ Suggestion

Hi from ts-api-utils.

We'd like to be able to check if an expression, passed as an argument of a call expression, is in a "const context". Checking for as const is fairly trivial as we can just search up the syntax tree, but checking for const type parameters seems impossible without using TypeScript internals.

With code examples:

We can currently check if foo is in a "const context" here fairly trivially:

const test1 = { foo: 1 } as const;

But can't do the same for foo in this example:

declare const fn: <const A>(param: A) => unknown;
const test2 = fn({ foo: 2 });
Proposal

Ideally, we would like an officially supported way to make such a check.

We currently have a PR in progress that works using ts internals, but we'd prefer not to rely on ts internals.

📃 Motivating Example

N/A

💻 Use Cases
  1. What do you want to use this for?
    determining whether a type is readonly
    https://github.com/eslint-functional/eslint-plugin-functional/issues/827

  2. What shortcomings exist with current approaches?
    There doesn't seem to be anyway official way to do this

  3. What workarounds are you using in the meantime?
    Use ts internals

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず const 型パラメーターの例を再現し、TypeScript compiler API と ts-api-utils PR #519 で使用されている既存の内部アプローチを確認します。公式にサポートされた API によって、readonly-type のユースケースを含め、引数式が const コンテキストにあるかどうかを TypeScript の内部実装に依存せず判定できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。