Feature request: enforce generic types when passed to `ReactFireOptions`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- firebase, react, typescript
- Domain
- frontend
Research direction
Start by searching the TypeScript sources for the ReactFireOptions interface and the occurrences of {[key: string]: unknown}. Update the option types so explicit generics constrain initialData and startWithValue, replace the applicable index signatures with Record<string, unknown>, and verify that mismatched generic values are rejected while untyped options remain usable.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 403
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 10
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FirebaseExtended/reactfire
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FirebaseExtended/reactfire#790 · 2 comments ·
-
v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
FirebaseExtended/reactfire#789 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
FirebaseExtended/reactfire#788 ·
All issues in FirebaseExtended/reactfire
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
melgarafael/DeskcommCRM#1812 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
prisma/prisma-cli#309 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gregwebs/pi-quota-dispatcher#26 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
openwatersio/slackwater.xyz#124 ·
Maintainers usually reply within 1 day
-
agent-reported area/browser area/docs documentation good first issue hacktoberfest help wanted P2
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days