microsoft / microsoft/TypeScript

String#matchAll is too restrictive in its parameter type

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

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

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

説明

🔎 Search Terms

matchAll

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about RegExps and matchAll
⏯ Playground Link

https://www.typescriptlang.org/play?target=7#code/MYewdgzgLgBAtgTwMIFdojgeQEYCsCmwsAvDAN4CwAUDLTAFQDaAygnNiADYB0cAhlGAALAIKdOAXQAU0AE4BLMAHMAXDDmKlASjUBxfGHyyBIWQB4ASviUBRAB4AHe4RGzjCAHzlqdGAF9qAKpqUEgufG5OECUpRm54gHIAMxAQBN4BYTFOKURUdCw8QigtCS0AbmogA

💻 Code
const myCustomObject = {
    *[Symbol.matchAll](string: string): Generator<RegExpExecArray> {
    }
}

console.log([...'foo'.matchAll(myCustomObject)]);
🙁 Actual behavior

TS rejects this code, because myCustomObject is not an instance of RegExp.

🙂 Expected behavior

Any value matching the following type should be accepted, including myCustomObject. The other parts of the RegExp object are not used.

type MatchAllRegExpLike = {
  [Symbol.matchAll](string: string): IterableIterator<RegExpExecArray>;
  // If the object has a [Symbol.match] property that is truthy, its flags are checked. However, neither
  // must be present, and even if it is present, [Symbol.match] doesn't have to be a function.
  readonly [Symbol.match]?: any;
  readonly flags?: string;
};
Additional information about the issue

This is distinct from #47310. That issue is about string-to-regexp conversion; this is about regexp-like objects.

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground の例から始めます。issue ではリポジトリのファイルもテストも指定されていません。String#matchAll が使用する宣言を追跡し、提案された MatchAllRegExpLike の形と比較してから、既存の matchAll の動作が引き続きカバーされた状態で、例がコンパイルされることを確認します。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
43/100

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

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