microsoft / microsoft/TypeScript

Better types for UrlSearchParams

オープン
#43,738 コメント 7 件 リアクション 13 件 担当者 0 名 GitHub で見る

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

Domain: lib.d.ts Experience Enhancement Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

Suggestion

🔍 Search Terms

Restrictive typing on UrlSearchParams

✅ 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

declare var URLSearchParams: {
    prototype: URLSearchParams;
    // new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
    new(init?: 
        | string
        | URLSearchParams
        | Record<string | number, string | number | boolean | string[] | number[] | boolean[]>
        | [string | number | boolean, string | number | boolean | string[] | number[] | boolean[]][]): URLSearchParams;
    toString(): string;
};

📃 Motivating Example

The actual typing design is more restrictive than the Javascript runtime itself.

💻 Use Cases

More possibilities to create strict typed UrlSearchParams objects:

let url = 'https://developer.microsoft.com'

const queryParams = new UrlSearchParams({
  key1: ["v1", "v2"],
  key2: ["v1", "v2", "v3"]
})

url = url + '?' + queryParams // https://developer.microsoft.com?key1=v1,v2&key2=v1,v2,v3

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

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

はじめの一歩

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

調査の方向性

まず、標準ライブラリにある URLSearchParams の宣言を見つけ、提案されているオーバーロードおよびその根拠となる例に照らして、コンストラクターの型付けを確認してください。サポートする入力形式を決める前に、周辺の型定義と関連する型テストを確認してください。完了の条件は、出力される JavaScript やランタイムの動作を変更せずに、宣言が意図したより厳密な形式を受け入れることです。

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

評価

技術スタック
javascript, typescript
領域
api, web-dev
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
32/100

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

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