Feature request: enforce generic types when passed to `ReactFireOptions`
还没有人认领这个 Issue。
评估
- 难度
- 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 小时
- 30 天内合并 PR
- 10
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
FirebaseExtended/reactfire 的其他 Issue
-
难度 5/5 一周以上 新手友好度 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 一周以上 新手友好度 35/100
FirebaseExtended/reactfire#788 ·
查看 FirebaseExtended/reactfire 的全部 Issue
相似的 Issue
-
ADD openalgo未关闭template
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
factory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
难度 2/5 1-3 小时 新手友好度 90/100
维护者通常 1 天内回复
-
bug Needs: Triage :mag:
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/fluentui-contrib#671 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
sveltejs/acorn-typescript#150 ·
-
难度 2/5 1-3 小时 新手友好度 78/100