Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#383 0 comentários 3 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
45/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
firebase, react, typescript
Domínio
frontend

Direção de pesquisa

Comece pesquisando nos fontes TypeScript pela interface ReactFireOptions e pelas ocorrências de {[key: string]: unknown}. Atualize os tipos das opções para que os genéricos explícitos restrinjam initialData e startWithValue, substitua as assinaturas de índice aplicáveis por Record<string, unknown> e verifique se valores genéricos incompatíveis são rejeitados, enquanto opções sem tipagem continuam utilizáveis.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
3.6k
Forks
403
Merge médio
5d 1h
PRs com merge (30d)
10

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de FirebaseExtended/reactfire

Todas as issues de FirebaseExtended/reactfire

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.