Feature request: enforce generic types when passed to `ReactFireOptions`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- firebase, react, typescript
- Área
- frontend
Línea de trabajo
Comienza buscando en los fuentes TypeScript la interfaz ReactFireOptions y las apariciones de {[key: string]: unknown}. Actualiza los tipos de opciones para que los genéricos explícitos restrinjan initialData y startWithValue, reemplaza las firmas de índice aplicables por Record<string, unknown> y verifica que los valores genéricos que no coincidan sean rechazados, mientras que las opciones sin tipar sigan siendo utilizables.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 3.6k
- Forks
- 403
- Merge medio
- 5 d 1 h
- PR fusionados (30 d)
- 10
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FirebaseExtended/reactfire
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
FirebaseExtended/reactfire#790 · 2 comentarios ·
-
v5
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
FirebaseExtended/reactfire#789 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
FirebaseExtended/reactfire#788 ·
Todos los issues de FirebaseExtended/reactfire
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
bcgov/bc-wallet-mobile#4761 · 1 comentario ·
-
external-issue to-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
area-deployment area-integrations triage:bot-seen
Dificultad 2/5 Medio día Aptitud para principiantes 86/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100