-
Notifications
You must be signed in to change notification settings - Fork 107
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
refactor(types): enable noImplicitAny for transaction.ts & request.ts #305
Conversation
…into noImplicitAny
… into noImplicitAny
noImplicitAny: request.ts
NoImplicitAny: Transaction.ts
There was a problem hiding this 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 :)
@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 |
… into noImplicitAny-converge
…odejs-datastore into noImplicitAny-converge
@JCIV-SE this looks like it needs a little love :) Is this going to get a look soon? |
@JustinBeckwith Yup! It's next on the list 👍 |
|
||
callback = callback || (() => {}); | ||
delete(keys: Entities): | ||
void|Promise<google.datastore.v1.Datastore.CommitCallback>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@@ -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>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Fixes #252 (it's a good idea to open an issue first for discussion)