Skip to content

Fix packages/firestore/ usages of @ts-ignore. #1882

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

Merged
merged 4 commits into from
Jun 17, 2019
Merged
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
8 changes: 3 additions & 5 deletions packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,19 @@ export function makeCredentialsProvider(

switch (credentials.type) {
case 'gapi':
const client = credentials.client;
// Make sure this is a Gapi client.
const client = credentials.client as Gapi;
// Make sure this really is a Gapi client.
assert(
!!(
typeof client === 'object' &&
client !== null &&
// @ts-ignore
client['auth'] &&
// @ts-ignore
client['auth']['getAuthHeaderValueForFirstParty']
),
'unexpected gapi interface'
);
return new FirstPartyCredentialsProvider(
client as Gapi,
client,
credentials.sessionIndex || '0'
);

Expand Down
4 changes: 1 addition & 3 deletions packages/firestore/src/local/shared_client_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ export class SharedOnlineState {

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

if (validData) {
Expand Down
16 changes: 7 additions & 9 deletions packages/firestore/src/platform_browser/webchannel_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
ErrorCode,
EventType,
WebChannel,
WebChannelOptions,
XhrIo
// @ts-ignore
} from '@firebase/webchannel-wrapper';

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

this.modifyHeadersForRequest(request.initMessageHeaders, token);
this.modifyHeadersForRequest(request.initMessageHeaders!, token);

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

const url = urlParts.join('');
Expand Down Expand Up @@ -345,11 +344,10 @@ export class WebChannelConnection implements Connection {
// (and only errors) to be wrapped in an extra array. To be forward
// compatible with the bug we need to check either condition. The latter
// can be removed once the fix has been rolled out.
// tslint:disable-next-line:no-any msgData.error is not typed.
const msgDataAsAny: any = msgData;
const error =
// tslint:disable-next-line:no-any msgData.error is not typed.
(msgData as any).error ||
// @ts-ignore
(msgData[0] && msgData[0].error);
msgDataAsAny.error || (msgDataAsAny[0] && msgDataAsAny[0].error);
if (error) {
log.debug(LOG_TAG, 'WebChannel received error:', error);
// error.status will be a string like 'OK' or 'NOT_FOUND'.
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/platform_node/grpc_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export class GrpcConnection implements Connection {
private cachedStub: GeneratedGrpcStub | null = null;

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

private ensureActiveStub(): GeneratedGrpcStub {
Expand Down
1 change: 1 addition & 0 deletions packages/firestore/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { assert } from './assert';

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

// tslint:disable-next-line:class-as-namespace
export class AutoId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ describe('WebStorageSharedClientState', () => {
// We capture the listener here so that we can invoke it from the local
// client. If we directly relied on WebStorage listeners, we would not
// receive events for local writes.
// @ts-ignore
window.addEventListener = (type: string, callback: WebStorageCallback) => {
window.addEventListener = (type: string, callback: unknown) => {
if (type === 'storage') {
webStorageCallbacks.push(callback);
webStorageCallbacks.push(callback as WebStorageCallback);
}
};
window.removeEventListener = () => {};
Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/test/unit/remote/node/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
WatchTargetChangeState
} from '../../../../src/remote/watch_change';
import { Code, FirestoreError } from '../../../../src/util/error';
import { Indexable } from '../../../../src/util/misc';
import * as obj from '../../../../src/util/obj';
import * as types from '../../../../src/util/types';
import { addEqualityMatcher } from '../../../util/equality_matcher';
Expand Down Expand Up @@ -156,8 +157,9 @@ describe('Serializer', () => {
const actualProtobufjsProto: ProtobufJS.Message = ValueMessage.fromObject(
actualJsonProto
);
// @ts-ignore
expect(actualProtobufjsProto[valueType]).to.deep.equal(protobufJsValue);
expect((actualProtobufjsProto as Indexable)[valueType]).to.deep.equal(
protobufJsValue
);

// Convert protobufjs back to JSON.
const returnJsonProto = ValueMessage.toObject(
Expand Down
11 changes: 7 additions & 4 deletions packages/firestore/test/util/equality_matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { use } from 'chai';
import { Equatable } from '../../src/util/misc';

/**
* @file This file provides a helper function to add a matcher that matches
Expand All @@ -28,10 +29,12 @@ function customDeepEqual(left: unknown, right: unknown): boolean {
/**
* START: Custom compare logic
*/
// @ts-ignore
if (left && typeof left.isEqual === 'function') return left.isEqual(right);
// @ts-ignore
if (right && typeof right.isEqual === 'function') return right.isEqual(left);
if (typeof left === 'object' && left && 'isEqual' in left) {
return (left as Equatable<unknown>).isEqual(right);
}
if (typeof right === 'object' && right && 'isEqual' in right) {
return (right as Equatable<unknown>).isEqual(left);
}
/**
* END: Custom compare logic
*/
Expand Down
1 change: 1 addition & 0 deletions packages/webchannel-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"typings": "src/index.d.ts",
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
}
Expand Down
56 changes: 56 additions & 0 deletions packages/webchannel-wrapper/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* 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.
*/

// TODO(mikelehen): Flesh out proper types (or figure out how to generate via
// clutz or something).
export class XhrIo {}
export const ErrorCode: any;
export const EventType: any;
export namespace WebChannel {
export type EventType = any;
export const EventType: any;
}

type StringMap = { [key: string]: string };

export interface WebChannelOptions {
messageHeaders?: StringMap;
initMessageHeaders?: StringMap;
messageContentType?: string;
messageUrlParams?: StringMap;
clientProtocolHeaderRequired?: boolean;
concurrentRequestLimit?: number;
supportsCrossDomainXhr?: boolean;
testUrl?: string;
sendRawJson?: boolean;
httpSessionIdParam?: string;
httpHeadersOverwriteParam?: string;
backgroundChannelTest?: boolean;
forceLongPolling?: boolean;
fastHandshake?: boolean;
disableRedac?: boolean;
clientProfile?: string;
internalChannelParams?: { [key: string]: boolean | number };
xmlHttpFactory?: unknown;
requestRefreshThresholds?: { [key: string]: number };
}

export interface WebChannelTransport {
createWebChannel(url: string, options: WebChannelOptions): any;
}

export function createWebChannelTransport(): WebChannelTransport;