Feature request: enforce generic types when passed to `ReactFireOptions`
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- firebase, react, typescript
- 領域
- frontend
調査の方向性
まず、TypeScript ソースで ReactFireOptions インターフェースと {[key: string]: unknown} の出現箇所を検索します。明示的なジェネリックが initialData と startWithValue を制約するようにオプションの型を更新し、該当するインデックスシグネチャを Record<string, unknown> に置き換え、型の一致しないジェネリック値が拒否される一方で、型指定のないオプションは引き続き使用できることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FirebaseExtended/reactfire のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
FirebaseExtended/reactfire#801 ·
-
v5
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
FirebaseExtended/reactfire#793 ·
-
v5
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
FirebaseExtended/reactfire#790 · コメント 2 件 ·
-
v5
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
FirebaseExtended/reactfire#789 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
FirebaseExtended/reactfire#788 ·
FirebaseExtended/reactfire の issue をすべて見る
似ている issue
-
resources
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
railmapgen/rmg-palette#2445 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
danielmiessler/LifeOS#2242 ·
メンテナーはふだん 5 日以内に返信
-
good first issue hacktoberfest help wanted translation
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
callstackincubator/appduct#129 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100