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

Conversation

mikelehen
Copy link
Contributor

No description provided.

Michael Lehenbauer added 4 commits August 8, 2019 16:01
tsconfig.base.json enables "strict" now which implicitly enables
"strictFunctionTypes", "strictNullChecks", and "noImplicitAny" so we don't need
to do so explicitly.

Disabling "alwaysStrict" and "noImplicitThis" was unnecessary since we have no
violations.
): 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).

);
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.

@@ -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.

) 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.

@@ -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

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Hey! This PR rewrites all my TypeScript voodoo from last year. And now you are asking me to approve a rewrite!? :)

I think there is an issue with the DelayedPromises. It's unrelated to this PR, but it might be a small enough fix to make along with the rest of the changes. If not, we can fix it in a follow up (with a more suitable PR title).

this,
timerId,
delayMs,
op,
op => this.removeDelayedOperation(op)
op => this.removeDelayedOperation(op as DelayedOperation<unknown>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm. This looks wrong to me. Not the code you wrote - but don't we need to call removeDelayedOperation and delayedOperations.push with delayedOp?

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 agree it looks wrong, but it's actually right because unlike the line above, the removal callback is called with the delayedOp. It's pretty confusing though since we call it "op" which is already an in-scope variable. I renamed it to removedOp to avoid ambiguity. I tried removedDelayedOp but that is a bit long and prettier ended up splitting DelayedOperation<unknown> into 3 lines which looked horrible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. Yes, that is confusing. I even checked out the branch locally and it didn't clear up this confusion :/ Thanks for renaming.

@mikelehen mikelehen changed the base branch from mikelehen/firestore-strict-noImplicitThis to master August 9, 2019 18:52
@mikelehen mikelehen merged commit 3f9e8e8 into master Aug 9, 2019
@mikelehen mikelehen deleted the mikelehen/firestore-strict-bind-call-apply branch August 9, 2019 20:10
mikelehen pushed a commit that referenced this pull request Aug 12, 2019
@firebase firebase locked and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants