Skip to content

Fixed gc of Data type #8804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/soft-lizards-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/data-connect": patch
---

Fixed type erasure of the `Data` type
7 changes: 6 additions & 1 deletion common/api-review/data-connect.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export function executeMutation<Data, Variables>(mutationRef: MutationRef<Data,
// @public
export function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;

// @public (undocumented)
export const fdcSymbol: unique symbol;

// @public
export function getDataConnect(options: ConnectorConfig): DataConnect;

Expand Down Expand Up @@ -124,7 +127,9 @@ export type OnErrorSubscription = (err?: FirebaseError) => void;
export type OnResultSubscription<Data, Variables> = (res: QueryResult<Data, Variables>) => void;

// @public (undocumented)
export interface OperationRef<_Data, Variables> {
export interface OperationRef<Data, Variables> {
// (undocumented)
[fdcSymbol]?: Data;
// (undocumented)
dataConnect: DataConnect;
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/data-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/src/index.d.ts",
"typings": "./dist/public.d.ts",
"nyc": {
"extension": [
".ts"
Expand Down
5 changes: 4 additions & 1 deletion packages/data-connect/src/api/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export interface OpResult<Data> {
fetchTime: string;
}

export interface OperationRef<_Data, Variables> {
export const fdcSymbol = Symbol();

export interface OperationRef<Data, Variables> {
name: string;
variables: Variables;
refType: ReferenceType;
dataConnect: DataConnect;
[fdcSymbol]?: Data; // Never used, just here to ensure that the Data type doesn't get erased.
}

export interface DataConnectResult<Data, Variables> extends OpResult<Data> {
Expand Down
45 changes: 45 additions & 0 deletions packages/data-connect/test/unit/typings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { deleteApp, initializeApp } from '@firebase/app';
import { DataConnect, getDataConnect, QueryRef, queryRef } from '../../src/api';
describe('Typings', () => {
it('should properly infer the type', async () => {
interface MyData {
extraField: boolean;
}
const app = initializeApp({ projectId: 'a' }, 'test');
const extendedType = Object.assign(
queryRef<MyData, undefined>(
getDataConnect({ connector: 'c', location: 'l', service: 'n' }),
'',
undefined
),
{
__abc: true
}
);
function myFn<Data, Variables>(
queryRef: QueryRef<Data, Variables>
): { data: Data } {
const data = {} as Data;
return { data };
}
myFn(extendedType).data.extraField;
await deleteApp(app);
});
});
Loading