Skip to content
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

refactor(types): enable noImplicitAny for transaction.ts & request.ts #305

Merged
merged 36 commits into from Feb 8, 2019
Merged

refactor(types): enable noImplicitAny for transaction.ts & request.ts #305

merged 36 commits into from Feb 8, 2019

Conversation

josecervino
Copy link

@josecervino josecervino commented Jan 19, 2019

Fixes #252 (it's a good idea to open an issue first for discussion)

  • Tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 19, 2019
@josecervino josecervino changed the title NoImplicitAny: [FINAL] Transaction & Request Final NoImplicitAny: transaction.ts & request.ts Jan 19, 2019
@JustinBeckwith JustinBeckwith changed the title NoImplicitAny: transaction.ts & request.ts refactor(types): enable noImplicitAny for transaction.ts & request.ts Jan 21, 2019
Copy link
Contributor

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

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

Just a first pass. Will come back around with more detail after feedback is addressed :)

src/entity.ts Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
@josecervino
Copy link
Author

@JustinBeckwith Thanks for taking the time out to look this over! I know it wasn't easy with so many fractured commits, I'm going to be making it a habit to keep it to one commit per issue. In general, a lot of the convoluted, unnecessary logic was created to pass the linter/formatter. I'll fix it asap

src/index.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/transaction.ts Outdated Show resolved Hide resolved
src/transaction.ts Outdated Show resolved Hide resolved
src/transaction.ts Outdated Show resolved Hide resolved
system-test/datastore.ts Outdated Show resolved Hide resolved
test/transaction.ts Outdated Show resolved Hide resolved
@JustinBeckwith
Copy link
Contributor

@JCIV-SE this looks like it needs a little love :) Is this going to get a look soon?

@josecervino
Copy link
Author

@JustinBeckwith Yup! It's next on the list 👍


callback = callback || (() => {});
delete(keys: Entities):
void|Promise<google.datastore.v1.Datastore.CommitCallback>;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to explicitly return void here

Copy link
Author

Choose a reason for hiding this comment

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

Agreed, but I added the void to solve this error:

Property 'delete' in type 'Transaction' is not assignable to the same property in base type 'DatastoreRequest'.
  Type '(entities: any) => void' is not assignable to type '{ (keys: any): Promise<CommitCallback>; (keys: any, callback: CommitCallback): void; (keys: any, gaxOptions: CallOptions, callback: CommitCallback): void; }'.
    Type 'void' is not assignable to type 'Promise<CommitCallback>'.

delete in transaction.ts has a void return annotation, and when changed to the same Promise there's an error asking explicitly for an any or void return annotation. I kept the promise to follow the "no callback = return promise" rule.

Should I make them all void and remove the promise return annotation from the method definition? (if all method overloads have the same return annotation, do we really need the overloads?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well hold on nah - what does CommitCallback have in it's type? Is it a callback function type? The answer here may be to return Promise<void>.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, CommitCallback is a callback function type. I also tried Promise<void> but I'm getting the same errors. I'll ask around to see if we can come up with something using feedback from an IDE

}

options = options || {};
get(keys: Entities,
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning the Entity or a Stream doesn't feel quite right. What am I missin here?

Copy link
Author

Choose a reason for hiding this comment

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

I admit the reasoning isn't 100% here. get relies on createReadStream which returns a stream, but get is expecting something iterator-related:

Type 'Stream' must have a '[Symbol.iterator]()' method that returns an iterator.

826       const [[deletedEntity], [fetchedEntity]] = await Promise.all([

Changing it to Promise<Entity> works well - lmk your take on it :)

callback: GetCallback): void;
get(keys: Entities, optionsOrCallback?: CreateReadStreamOptions|GetCallback,
cb?: GetCallback): void|Promise<Entity|Stream> {
const options =
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't doing this null check in other places, so I don't think it's entirely needed.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I agree, I'd prefer the consistency - the problem is that typeof null evalutes to 'object' in JS (thank you C) and a test uses null to trigger options be set to an object literal:

it('should default options to an object', done => {
        request.get(keys, null, err => {  // 2nd arg 'null' is what's being used to trigger the options object correction logic
          assert.ifError(err);

          const spy = request.createReadStream.getCall(0);
          assert.deepStrictEqual(spy.args[1], {});
          done();
        });
      });

Was thinking we should actually add the null check in other places because this doesn't tend to be accounted for

src/request.ts Show resolved Hide resolved
@@ -938,17 +959,21 @@ class DatastoreRequest {
* const apiResponse = data[0];
* });
*/
save(entities, gaxOptions?, callback?) {
save(entities: Entities, gaxOptions?: CallOptions):
void|Promise<google.datastore.v1.ICommitResponse>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need the void here

Copy link
Author

Choose a reason for hiding this comment

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

Getting the same error/problem as delete - I'll figure something out

src/request.ts Show resolved Hide resolved
test/transaction.ts Show resolved Hide resolved
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable noImplicitAny in the tsconfig
5 participants