Skip to content

Commit 1c28ffe

Browse files
author
Michael Lehenbauer
authored
Fix packages/firestore/ usages of @ts-ignore. (#1882)
* Fix packages/firestore/ usages of @ts-ignore. I left the equality_matcher.ts ones for the code we copy/pasted in, but fixed the rest.
1 parent fe87a29 commit 1c28ffe

File tree

10 files changed

+84
-28
lines changed

10 files changed

+84
-28
lines changed

packages/firestore/src/api/credentials.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -309,21 +309,19 @@ export function makeCredentialsProvider(
309309

310310
switch (credentials.type) {
311311
case 'gapi':
312-
const client = credentials.client;
313-
// Make sure this is a Gapi client.
312+
const client = credentials.client as Gapi;
313+
// Make sure this really is a Gapi client.
314314
assert(
315315
!!(
316316
typeof client === 'object' &&
317317
client !== null &&
318-
// @ts-ignore
319318
client['auth'] &&
320-
// @ts-ignore
321319
client['auth']['getAuthHeaderValueForFirstParty']
322320
),
323321
'unexpected gapi interface'
324322
);
325323
return new FirstPartyCredentialsProvider(
326-
client as Gapi,
324+
client,
327325
credentials.sessionIndex || '0'
328326
);
329327

packages/firestore/src/local/shared_client_state.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ export class SharedOnlineState {
462462

463463
const validData =
464464
typeof onlineState === 'object' &&
465-
// @ts-ignore Should allow arbitrary string index when checking to see
466-
// if that string is a valid enum value.
467-
OnlineState[onlineState.onlineState] !== undefined &&
465+
onlineState.onlineState in OnlineState &&
468466
typeof onlineState.clientId === 'string';
469467

470468
if (validData) {

packages/firestore/src/platform_browser/webchannel_connection.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
ErrorCode,
2121
EventType,
2222
WebChannel,
23+
WebChannelOptions,
2324
XhrIo
24-
// @ts-ignore
2525
} from '@firebase/webchannel-wrapper';
2626

2727
import { isReactNative } from '@firebase/util';
@@ -193,7 +193,7 @@ export class WebChannelConnection implements Connection {
193193
'/channel'
194194
];
195195
const webchannelTransport = createWebChannelTransport();
196-
const request = {
196+
const request: WebChannelOptions = {
197197
// Background channel test avoids the initial two test calls and decreases
198198
// initial cold start time.
199199
// TODO(dimond): wenboz@ mentioned this might affect use with proxies and
@@ -224,7 +224,7 @@ export class WebChannelConnection implements Connection {
224224
forceLongPolling: this.forceLongPolling
225225
};
226226

227-
this.modifyHeadersForRequest(request.initMessageHeaders, token);
227+
this.modifyHeadersForRequest(request.initMessageHeaders!, token);
228228

229229
// Sending the custom headers we just added to request.initMessageHeaders
230230
// (Authorization, etc.) will trigger the browser to make a CORS preflight
@@ -244,8 +244,7 @@ export class WebChannelConnection implements Connection {
244244
// ReactNative and so we exclude it, which just means ReactNative may be
245245
// subject to the extra network roundtrip for CORS preflight.
246246
if (!isReactNative()) {
247-
// @ts-ignore
248-
request['httpHeadersOverwriteParam'] = '$httpHeaders';
247+
request.httpHeadersOverwriteParam = '$httpHeaders';
249248
}
250249

251250
const url = urlParts.join('');
@@ -345,11 +344,10 @@ export class WebChannelConnection implements Connection {
345344
// (and only errors) to be wrapped in an extra array. To be forward
346345
// compatible with the bug we need to check either condition. The latter
347346
// can be removed once the fix has been rolled out.
347+
// tslint:disable-next-line:no-any msgData.error is not typed.
348+
const msgDataAsAny: any = msgData;
348349
const error =
349-
// tslint:disable-next-line:no-any msgData.error is not typed.
350-
(msgData as any).error ||
351-
// @ts-ignore
352-
(msgData[0] && msgData[0].error);
350+
msgDataAsAny.error || (msgDataAsAny[0] && msgDataAsAny[0].error);
353351
if (error) {
354352
log.debug(LOG_TAG, 'WebChannel received error:', error);
355353
// error.status will be a string like 'OK' or 'NOT_FOUND'.

packages/firestore/src/platform_node/grpc_connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export class GrpcConnection implements Connection {
8686
private cachedStub: GeneratedGrpcStub | null = null;
8787

8888
constructor(protos: grpc.GrpcObject, private databaseInfo: DatabaseInfo) {
89-
// @ts-ignore
90-
this.firestore = protos['google']['firestore']['v1'];
89+
// tslint:disable-next-line:no-any
90+
this.firestore = (protos as any)['google']['firestore']['v1'];
9191
}
9292

9393
private ensureActiveStub(): GeneratedGrpcStub {

packages/firestore/src/util/misc.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { assert } from './assert';
1919

2020
export type EventHandler<E> = (value: E) => void;
21+
export type Indexable = { [k: string]: unknown };
2122

2223
// tslint:disable-next-line:class-as-namespace
2324
export class AutoId {

packages/firestore/test/unit/local/web_storage_shared_client_state.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ describe('WebStorageSharedClientState', () => {
205205
// We capture the listener here so that we can invoke it from the local
206206
// client. If we directly relied on WebStorage listeners, we would not
207207
// receive events for local writes.
208-
// @ts-ignore
209-
window.addEventListener = (type: string, callback: WebStorageCallback) => {
208+
window.addEventListener = (type: string, callback: unknown) => {
210209
if (type === 'storage') {
211-
webStorageCallbacks.push(callback);
210+
webStorageCallbacks.push(callback as WebStorageCallback);
212211
}
213212
};
214213
window.removeEventListener = () => {};

packages/firestore/test/unit/remote/node/serializer.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
WatchTargetChangeState
5555
} from '../../../../src/remote/watch_change';
5656
import { Code, FirestoreError } from '../../../../src/util/error';
57+
import { Indexable } from '../../../../src/util/misc';
5758
import * as obj from '../../../../src/util/obj';
5859
import * as types from '../../../../src/util/types';
5960
import { addEqualityMatcher } from '../../../util/equality_matcher';
@@ -156,8 +157,9 @@ describe('Serializer', () => {
156157
const actualProtobufjsProto: ProtobufJS.Message = ValueMessage.fromObject(
157158
actualJsonProto
158159
);
159-
// @ts-ignore
160-
expect(actualProtobufjsProto[valueType]).to.deep.equal(protobufJsValue);
160+
expect((actualProtobufjsProto as Indexable)[valueType]).to.deep.equal(
161+
protobufJsValue
162+
);
161163

162164
// Convert protobufjs back to JSON.
163165
const returnJsonProto = ValueMessage.toObject(

packages/firestore/test/util/equality_matcher.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { use } from 'chai';
19+
import { Equatable } from '../../src/util/misc';
1920

2021
/**
2122
* @file This file provides a helper function to add a matcher that matches
@@ -28,10 +29,12 @@ function customDeepEqual(left: unknown, right: unknown): boolean {
2829
/**
2930
* START: Custom compare logic
3031
*/
31-
// @ts-ignore
32-
if (left && typeof left.isEqual === 'function') return left.isEqual(right);
33-
// @ts-ignore
34-
if (right && typeof right.isEqual === 'function') return right.isEqual(left);
32+
if (typeof left === 'object' && left && 'isEqual' in left) {
33+
return (left as Equatable<unknown>).isEqual(right);
34+
}
35+
if (typeof right === 'object' && right && 'isEqual' in right) {
36+
return (right as Equatable<unknown>).isEqual(left);
37+
}
3538
/**
3639
* END: Custom compare logic
3740
*/

packages/webchannel-wrapper/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"type": "git",
2727
"url": "https://github.com/firebase/firebase-js-sdk.git"
2828
},
29+
"typings": "src/index.d.ts",
2930
"bugs": {
3031
"url": "https://github.com/firebase/firebase-js-sdk/issues"
3132
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// TODO(mikelehen): Flesh out proper types (or figure out how to generate via
19+
// clutz or something).
20+
export class XhrIo {}
21+
export const ErrorCode: any;
22+
export const EventType: any;
23+
export namespace WebChannel {
24+
export type EventType = any;
25+
export const EventType: any;
26+
}
27+
28+
type StringMap = { [key: string]: string };
29+
30+
export interface WebChannelOptions {
31+
messageHeaders?: StringMap;
32+
initMessageHeaders?: StringMap;
33+
messageContentType?: string;
34+
messageUrlParams?: StringMap;
35+
clientProtocolHeaderRequired?: boolean;
36+
concurrentRequestLimit?: number;
37+
supportsCrossDomainXhr?: boolean;
38+
testUrl?: string;
39+
sendRawJson?: boolean;
40+
httpSessionIdParam?: string;
41+
httpHeadersOverwriteParam?: string;
42+
backgroundChannelTest?: boolean;
43+
forceLongPolling?: boolean;
44+
fastHandshake?: boolean;
45+
disableRedac?: boolean;
46+
clientProfile?: string;
47+
internalChannelParams?: { [key: string]: boolean | number };
48+
xmlHttpFactory?: unknown;
49+
requestRefreshThresholds?: { [key: string]: number };
50+
}
51+
52+
export interface WebChannelTransport {
53+
createWebChannel(url: string, options: WebChannelOptions): any;
54+
}
55+
56+
export function createWebChannelTransport(): WebChannelTransport;

0 commit comments

Comments
 (0)