Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

fix(typescript): add correct type safety to zone#create#307

Merged
bcoe merged 2 commits intogoogleapis:masterfrom
callmehiphop:create-zone-request
Oct 16, 2019
Merged

fix(typescript): add correct type safety to zone#create#307
bcoe merged 2 commits intogoogleapis:masterfrom
callmehiphop:create-zone-request

Conversation

@callmehiphop
Copy link
Copy Markdown
Contributor

@callmehiphop callmehiphop commented Oct 15, 2019

So this isn't exactly the right way to fix this issue. A better solution would be to use generics in the common library, however that might be tricky/result in a sweeping breaking change. I'd like to offer this up as a temporary fix until we feel comfortable giving the types in the common lib some love.


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

Fixes #126 🦕

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 15, 2019
Comment thread src/zone.ts
(err: Error | null): void;
}

type Without<T, K> = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This made my brain melt. Can you add a quick comment letting the unsuspecting javascript developer know what's happening here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Caaan do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah, a comment would be great here 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, PTAL

Comment thread src/zone.ts
Comment thread src/zone.ts
): void | Promise<CreateZoneResponse> {
// tslint:disable-next-line no-any
const args = [config, callback!] as any;
ServiceObject.prototype.create.apply(this, args);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason why this couldn't be:

return super.create(config, callback);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My approach here was to make TypeScript think there wasn't a create method in the prototype chain so that we could override it with the correct signature. As a result we can't call super here because it thinks that method doesn't exist.

Comment thread src/zone.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 15, 2019

Codecov Report

Merging #307 into master will decrease coverage by 0.71%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #307      +/-   ##
==========================================
- Coverage   92.65%   91.93%   -0.72%     
==========================================
  Files           4        4              
  Lines         245      248       +3     
  Branches       47       47              
==========================================
+ Hits          227      228       +1     
- Misses          9       11       +2     
  Partials        9        9
Impacted Files Coverage Δ
src/index.ts 97.82% <ø> (ø) ⬆️
src/zone.ts 90.68% <40%> (-1.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd8d113...d47f193. Read the comment docs.

@JustinBeckwith
Copy link
Copy Markdown
Contributor

Nicely done @callmehiphop! This is both a.) elegant and b.) gross.

Copy link
Copy Markdown

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

this is looking good to me, a few clarifying questions 😄

Comment thread src/zone.ts
Comment thread src/zone.ts
@bcoe bcoe marked this pull request as ready for review October 16, 2019 16:57
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 16, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 16, 2019
@bcoe bcoe merged commit d5b78b8 into googleapis:master Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript: Zone#create should have required parameter of type CreateZoneRequest

5 participants