Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Feature request: enforce generic types when passed to `ReactFireOptions`

オープン
#383 コメント 0 件 リアクション 3 件 担当者 0 名 GitHub で見る

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
firebase, react, typescript
領域
frontend

調査の方向性

まず、TypeScript ソースで ReactFireOptions インターフェースと {[key: string]: unknown} の出現箇所を検索します。明示的なジェネリックが initialData と startWithValue を制約するようにオプションの型を更新し、該当するインデックスシグネチャを Record<string, unknown> に置き換え、型の一致しないジェネリック値が拒否される一方で、型指定のないオプションは引き続き使用できることを確認します。

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

説明

v5
Enforce generic types when passed to ReactFireOptions, update various types

Hey guys, will try to keep this short. Right now ReactFireOptions is generic on T but the type of initialData, which should be only of_ type T is of type T | any.

export interface ReactFireOptions<T = unknown> {
  idField?: string;
  initialData?: T | any;
  /**
   * @deprecated use initialData instead
   */
  startWithValue?: T | any;
  suspense?: boolean;
}

The result of this is that the generic parameter is useless, as we don't get any type enforcement on initialData. For example, this is fine:

interface MyInterface {
    thing: string;
}

const foo: ReactFireOptions<MyInterface> = {
    initialData: {
        thing: 2 // no complaints
    }
}

My suggestion is to change ReactFireOptions to this:

export interface ReactFireOptions<T = any> {
  idField?: string;
  initialData?: T;
  /**
   * @deprecated use initialData instead
   */
  startWithValue?: T;
  suspense?: boolean;
}

This still allows users to pass whatever they want to initialData when not supplying a generic type, but will cause Typescript to complain when using a generic type and the value passed to initialData does not match the provided type.

interface MyInterface {
    thing: string;
}

const foo: ReactFireOptions<MyInterface> = {
    initialData: {
        thing: 2 // complains, "Type 'number' is not assignable to type 'string'."
    }
}

Additionally, there are a few places using { [key: string]: unknown }, which can be expressed more clearly with Record<string, unknown>.

I have a branch with the following changes but I can't push it as I don't have permissions. Not sure if I need to ask for them somewhere.

Cheers! Great project, and I'm finding it very useful.

主要言語
TypeScript
スター
3.6k
フォーク
403
平均マージ
5日 1時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

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

FirebaseExtended/reactfire のほかの issue

FirebaseExtended/reactfire の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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