Skip to content

Enable strictBindCallApply. #2074

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 9 commits into from
Aug 9, 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
10 changes: 9 additions & 1 deletion packages/firestore/src/local/persistence_promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,18 @@ export class PersistencePromise<T> {
* to resolve.
*/
static forEach<R, S>(
collection: { forEach: (cb: (r: R, s?: S) => void) => void },
collection: { forEach: (cb: (r: R, s: S) => void) => void },
f:
| ((r: R, s: S) => PersistencePromise<void>)
| ((r: R) => PersistencePromise<void>)
): PersistencePromise<void>;
static forEach<R>(
collection: { forEach: (cb: (r: R) => void) => void },
f: (r: R) => PersistencePromise<void>
): PersistencePromise<void>;
static forEach<R, S>(
collection: { forEach: (cb: (r: R, s?: S) => void) => void },
f: (r: R, s?: S) => PersistencePromise<void>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split this into two overloads. One for collections with keys and values, one for collections with just keys. Without this, you get:

Argument of type 'S | undefined' is not assignable to parameter of type 'S'. Type 'undefined' is not assignable to type 'S'.

from the f.call(this, r, s) line below (for s being undefined).

): PersistencePromise<void> {
const promises: Array<PersistencePromise<void>> = [];
collection.forEach((r, s) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/firestore/src/util/async_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,15 @@ export class AsyncQueue {
`Attempted to schedule multiple operations with timer id ${timerId}.`
);

const delayedOp = DelayedOperation.createAndSchedule<unknown>(
const delayedOp = DelayedOperation.createAndSchedule<T>(
this,
timerId,
delayMs,
op,
op => this.removeDelayedOperation(op)
removedOp =>
this.removeDelayedOperation(removedOp as DelayedOperation<unknown>)
);
this.delayedOperations.push(delayedOp);
this.delayedOperations.push(delayedOp as DelayedOperation<unknown>);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this you get:

Type 'DelayedOperation' is not assignable to type 'CancelablePromise'.

for the return delayedOp below.


return delayedOp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describeFn('WebChannel', () => {
const makeUrl = conn.makeUrl.bind(conn);

it('includes project ID and database ID', () => {
const url = makeUrl('Commit', {});
const url = makeUrl('Commit');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a bogus extra parameter.

expect(url).to.equal(
'http://example.com/v1/projects/testproject/' +
'databases/(default)/documents:commit'
Expand Down
25 changes: 19 additions & 6 deletions packages/firestore/test/integration/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ export function isRunningAgainstEmulator(): boolean {
}

/**
* A wrapper around Jasmine's describe method that allows for it to be run with
* A wrapper around Mocha's describe method that allows for it to be run with
* persistence both disabled and enabled (if the browser is supported).
*/
export const apiDescribe = apiDescribeInternal.bind(null, describe);
apiDescribe.skip = apiDescribeInternal.bind(null, describe.skip);
apiDescribe.only = apiDescribeInternal.bind(null, describe.only);

function apiDescribeInternal(
describeFn: Mocha.IContextDefinition,
describeFn: Mocha.PendingSuiteFunction,
message: string,
testSuite: (persistence: boolean) => void
): void {
Expand All @@ -111,6 +107,23 @@ function apiDescribeInternal(
}
}

type ApiSuiteFunction = (
message: string,
testSuite: (persistence: boolean) => void
) => void;
interface ApiDescribe {
(message: string, testSuite: (persistence: boolean) => void): void;
skip: ApiSuiteFunction;
only: ApiSuiteFunction;
}

export const apiDescribe = apiDescribeInternal.bind(
null,
describe
) as ApiDescribe;
apiDescribe.skip = apiDescribeInternal.bind(null, describe.skip);
apiDescribe.only = apiDescribeInternal.bind(null, describe.only);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without these changes, we were getting two errors:

Argument of type 'PendingSuiteFunction' is not assignable to parameter of type 'IContextDefinition'. Type 'PendingSuiteFunction' is missing the following properties from type 'IContextDefinition': only, skip

For passing describe.skip to apiDescribeInternal() and:

Property 'skip' does not exist on type '(message: string, testSuite: (persistence: boolean) => void) => void'.ts(2339)

for assigning to apiDescribe.skip.

/** Converts the documents in a QuerySnapshot to an array with the data of each document. */
export function toDataArray(
docSet: firestore.QuerySnapshot
Expand Down
5 changes: 2 additions & 3 deletions packages/firestore/test/util/equality_matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export function addEqualityMatcher(): void {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const assertEql = (_super: (r: unknown, l: unknown) => boolean) => {
originalFunction = originalFunction || _super;
return function(this: unknown, ...args: unknown[]): void {
return function(this: unknown, expected?: unknown, msg?: unknown): void {
if (isActive) {
const [expected, msg] = args;
utils.flag(this, 'message', msg);
const actual = utils.flag(this, 'object');

Expand All @@ -106,7 +105,7 @@ export function addEqualityMatcher(): void {
/*showDiff=*/ true
);
} else if (originalFunction) {
originalFunction.apply(this, args);
originalFunction.call(this, expected, msg);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without these changes we were getting:

Argument of type 'unknown[]' is not assignable to parameter of type '[unknown, unknown]'.
Type 'unknown[]' is missing the following properties from type '[unknown, unknown]': 0, 1

}
};
};
Expand Down
1 change: 0 additions & 1 deletion packages/firestore/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../config/tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"strictBindCallApply": false,
"strictPropertyInitialization": false
},
"exclude": [
Expand Down