Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/tests_tsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Testing (tsd)

on:
pull_request:
branches:
- '**'
paths-ignore:
- 'docs/**'
- 'website/**'
- '.spellcheck.dict.txt'
- '**/*.md'
push:
branches:
- main
paths-ignore:
- 'docs/**'
- 'website/**'
- '.spellcheck.dict.txt'
- '**/*.md'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tsd:
name: tsd
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/cache/restore@v4
name: Yarn Cache Restore
id: yarn-cache
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-v1
- name: Yarn Install
uses: nick-fields/retry@v3
with:
timeout_minutes: 15
retry_wait_seconds: 60
max_attempts: 3
command: yarn
- name: tsd
run: yarn tests:tsd
- uses: actions/cache/save@v4
name: Yarn Cache Save
if: "${{ github.ref == 'refs/heads/main' }}"
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('yarn.lock') }}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint:spellcheck": "spellchecker --quiet --files=\"docs/**/*.md\" --dictionaries=\"./.spellcheck.dict.txt\" --reports=\"spelling.json\" --plugins spell indefinite-article repeated-words syntax-mentions syntax-urls frontmatter",
"tsc:compile": "tsc --project .",
"lint:all": "yarn lint && yarn lint:markdown && yarn lint:spellcheck && yarn tsc:compile",
"tests:tsd": "npx tsd packages/firestore",
"tests:ai:mocks": "yarn ts-node ./scripts/fetch_ai_mock_responses.ts && yarn ts-node ./packages/ai/__tests__/test-utils/convert-mocks.ts",
"tests:jest": "jest",
"tests:jest-watch": "jest --watch",
Expand Down Expand Up @@ -100,6 +101,7 @@
"spellchecker-cli": "^7.0.0",
"ts-jest": "^29.4.1",
"ts-node": "^10.9.2",
"tsd": "^0.33.0",
"typescript": "^5.9.2"
},
"resolutions": {
Expand Down
4 changes: 3 additions & 1 deletion packages/app/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ export function preferencesSetString(key: string, value: string): Promise<void>;
*
* This is required if you want to persist things like Auth sessions, Analytics device IDs, etc.
*/
export function setReactNativeAsyncStorage(asyncStorage: ReactNativeAsyncStorage): void;
export function setReactNativeAsyncStorage(
asyncStorage: ReactNativeFirebase.ReactNativeAsyncStorage,
): void;
1 change: 1 addition & 0 deletions packages/firestore/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ android/.settings
.eslintignore
type-test.ts
__tests__
*.test-d.ts
13 changes: 6 additions & 7 deletions packages/firestore/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export namespace FirebaseFirestoreTypes {
export type QueryFilterType = 'OR' | 'AND';

export interface QueryFieldFilterConstraint {
fieldPath: keyof T | FieldPath;
fieldPath: FieldPath;
operator: WhereFilterOp;
value: any;
}
Expand All @@ -77,7 +77,7 @@ export namespace FirebaseFirestoreTypes {
* e.g. Filter('name', '==', 'Ada')
*/
(
fieldPath: keyof T | FieldPath,
fieldPath: FieldPath | string,
operator: WhereFilterOp,
value: any,
): QueryFieldFilterConstraint;
Expand Down Expand Up @@ -894,7 +894,7 @@ export namespace FirebaseFirestoreTypes {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class AggregateField<T> {
/** A type string to uniquely identify instances of this class. */
type = 'AggregateField';
readonly type: 'AggregateField';
}

/**
Expand Down Expand Up @@ -923,14 +923,13 @@ export namespace FirebaseFirestoreTypes {
*/
export interface AggregateQuerySnapshot<
AggregateSpecType extends AggregateSpec,
AppModelType = DocumentData,
DbModelType extends DocumentData = DocumentData,
T extends DocumentData = DocumentData,
> {
/**
* The underlying query over which the aggregations recorded in this
* `AggregateQuerySnapshot` were performed.
*/
get query(): Query<AppModelType, DbModelType>;
get query(): Query<T>;

/**
* Returns the results of the aggregations performed over the underlying
Expand All @@ -953,7 +952,7 @@ export namespace FirebaseFirestoreTypes {
/**
* The underlying query for this instance.
*/
get query(): Query<unknown>;
get query(): Query;

/**
* Executes the query and returns the results as a AggregateQuerySnapshot.
Expand Down
72 changes: 72 additions & 0 deletions packages/firestore/lib/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expectType } from 'tsd';
import firebase, {
collection,
doc,
FirebaseFirestoreTypes,
getDoc,
increment,
onSnapshot,
query,
serverTimestamp,
setDoc,
Timestamp,
updateDoc,
where,
} from '.';

export const tests = [
async () => {
type DocShape = { name: string; age: number; createdAt: Timestamp };
const usersCollection = collection<DocShape>(firebase(), 'collectionName');
expectType<FirebaseFirestoreTypes.CollectionReference<DocShape>>(usersCollection);
const userDoc = doc(usersCollection, 'doc-id');
expectType<FirebaseFirestoreTypes.DocumentReference<DocShape>>(userDoc);
const snapshot = await getDoc(userDoc);
expectType<FirebaseFirestoreTypes.DocumentSnapshot<DocShape>>(snapshot);
expectType<DocShape | undefined>(snapshot.data());

updateDoc(userDoc, { age: 20, createdAt: serverTimestamp() });
updateDoc(userDoc, { age: increment(1), createdAt: serverTimestamp() });

setDoc(userDoc, {
name: 'hi',
age: 30,
createdAt: Timestamp.fromDate(new Date()),
});

const q = query(usersCollection, where('not-typed-intentionally', '==', 'CA'));
onSnapshot(q, s => {
for (const doc of s.docs) {
expectType<DocShape>(doc.data());
}
});

onSnapshot(q, {
next: s => {
for (const doc of s.docs) {
expectType<DocShape>(doc.data());
}
},
error: e => {
expectType<Error>(e);
},
});

usersCollection.where('age', '>', 18).onSnapshot(s => {
for (const doc of s.docs) {
expectType<DocShape>(doc.data());
}
});

where('a', '!=', 3);
where('a', '<', 3);
where('a', '<=', 3);
where('a', '==', 3);
where('a', '>', 3);
where('a', '>=', 3);
where('a', 'array-contains', 3);
where('a', 'array-contains-any', 3);
where('a', 'in', 3);
where('a', 'not-in', 3);
},
];
4 changes: 3 additions & 1 deletion packages/firestore/lib/modular/Bytes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export declare class Bytes extends FirestoreBlob {
import { FirebaseFirestoreTypes } from '..';

export declare class Bytes extends FirebaseFirestoreTypes.Blob {
static fromBase64String(base64: string): Bytes;

static fromUint8Array(array: Uint8Array): Bytes;
Expand Down
Loading
Loading