googleapis / googleapis/google-cloud-node

[FR] Typed version of doc(), collection() and collectionGroup methods

Open
#7,472 10 comments 4 reactions 1 assignee Claimed by @cherylEnkidu View on GitHub
api: firestore library: nodejs-firestore priority: p3 type: feature request
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

`Firestore.doc(...)`, `Firestore.collection(...)` and `Firestore.collectionGroup(...)` all return Typed return value and the type is carried over nicely to all underlying functions.

However, we have no way to actually nicely input the type. This forces to write code that is prone to breaking as it contains casts:
```ts
const collectionRef = firestore.collection('contracts/' + customerKey + '/drafts') as CollectionReference
```

The correct TS way would be to be able to write
```ts
firestore.collection('contracts/' + customerKey + '/drafts')....
```

The current type is
```ts
collection(collectionPath: string): CollectionReference;
```

It should be
```ts
collection(collectionPath: string): CollectionReference
```

The same should be applied for .doc and .collectionGroup.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.