[REQUIRED] Describe your environment
- Operating System version: -
- Browser version: -
- Firebase SDK version: 9.1.3
- Firebase Product: Firestore
- Typescript 4.4.4
[REQUIRED] Describe the problem
Steps to reproduce:
Create a function which takes an argument of type T, and inside it call any firestore functions that receive WithFieldValue or PartialWithFieldValue (e.g. setDoc, addDoc, etc) with that value T.
Result is that TypeScript will say nope:
Argument of type 'T' is not assignable to parameter of type 'WithFieldValue'.
this creates a problem in that every call to these functions require a type cast, which is not ideal.
Relevant Code:
class Bla<T> {
withFieldValueT(value: WithFieldValue<T>) {
}
withT(value: T) {
// doesn't work
this.withFieldValueT(value);
// works but has cast
this.withFieldValueT(value as unknown as WithFieldValue<T>);
}
}
const bla = new Bla<{ id: string, foo: number }>();
bla.withFieldValueT({ id: '', foo: 123 });
bla.withT({ id: '123', foo: 123 });
TS playground link
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
Create a function which takes an argument of type
T, and inside it call any firestore functions that receiveWithFieldValueorPartialWithFieldValue(e.g.setDoc,addDoc, etc) with that valueT.Result is that TypeScript will say nope:
this creates a problem in that every call to these functions require a type cast, which is not ideal.
Relevant Code:
TS playground link