firebase / firebase/firebase-admin-node

Typescript errors TS2345 on update method

Aperta
#2,372 1 commento 1 reazione 0 assegnatari Vedi su GitHub
needs-triage
Lingua principale
TypeScript
Stelle
1.7k
Fork
419
Merge medio
3g 10h
PR unite (30g)
16

Descrizione

### [READ] Step 1: Are you in the right place?
Yes

### [REQUIRED] Step 2: Describe your environment

* Operating System version: Ubuntu 22.04
* Firebase SDK version: 11.11.0
* Firebase Product: firebase-admin
* Node.js version: 18
* NPM version: 9.7.2

### [REQUIRED] Step 3: Describe the problem

`DocumentSnapshot` or `DocumentReference` `update` method can't be used with typed interfaces. I get the following typescript error

```
TS2345: Argument of type  MyInterface  is not assignable to parameter of type

{ [x: string]: any; } & AddPrefixToKeys
```

#### Relevant Code:

Calls like this will get errors:

```typescript
const data = snapshot.data() as MyInterface;
db.collection(`anypath`).doc(id).update(data)

```

Quick workaround would be to cast it as any

```typescript
db.collection(`anypath`).doc(id).update(data as any)
```

But it would require to refactor every `update` call which can be painful for large projects.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by reproducing the reported TS2345 error with the typed-interface example and inspect the DocumentSnapshot and DocumentReference update entry points. Compare the accepted update types with the MyInterface example. Done means typed interface data can be passed to update without casting to any, with the relevant type behavior verified.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
node.js, typescript
Ambito
database
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.