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

feat(types): Add Typescript definitions. #1676

Merged
merged 5 commits into from Aug 20, 2019
Merged

Conversation

mastermatt
Copy link
Member

Fixes: #1670

Copies over the existing types and tests from DefinitelyTyped.
Includes updates to bring them up to date with 11.0

Fixes: nock#1670

Copies over the existing types and tests from DefinitelyTyped.
Includes updates to bring them up to date with 11.0
@paulmelnikow
Copy link
Member

Wow, this looks great! I want to look through this a bit. There are a few methods in here that I think are not documented and therefore I’d consider internal, and I think there’s a conflict between what’s here and in the release notes for .reply(), probably my mistake, so I want to reconcile that.

It’s exciting to have these included here!

@paulmelnikow
Copy link
Member

There are two methods which I think are internal and should be removed:

  • getTotalDelay()
  • shouldPersist()

Do you agree?

@paulmelnikow
Copy link
Member

I have some suggested edits. I moved one type before its first use, and tweaked some naming. The idea is to reserve "callback" for a Node-style callback and use ReplyFn in place of ReplyCallback. I also reordered the .reply() entries, so the synchronous one is first and the Node-style callbacks are last.

I'm pushing the edits to this branch for the sake of simplicity, though if you prefer to do something else, feel free to revert of edit further.

@mastermatt
Copy link
Member Author

I'm fine with removing those two fns. Neither are documented. getTotalDelay is confusing anyway since it doesn't include all of the delays. shouldPersist seems like a valid external getter, but I don't have a strong opinion on it.

The naming changes look good, however, the order of the reply overrides are important as TS does a top-down search looking for a match. As is, it's unable to determine the correct signature for the reply function in some cases and dtslint shows about a dozen errors in the test file.

@mastermatt
Copy link
Member Author

I've made those changes. This is ready for review again.

) => ReplyBody | Promise<ReplyBody>,
headers?: ReplyHeaders
): Scope
reply(responseCode?: StatusCode, body?: Body, headers?: ReplyHeaders): Scope
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if we accept e.g. .reply(undefined, "foobar") as this indicates?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to double check, but yes. That would work and result in the status code defaulting to 200.

@mastermatt mastermatt merged commit 2e56fb0 into nock:next Aug 20, 2019
@mastermatt mastermatt deleted the add-ts-defs branch August 20, 2019 01:32
@nockbot
Copy link
Collaborator

nockbot commented Aug 20, 2019

🎉 This PR is included in version 11.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@paulmelnikow
Copy link
Member

This is amazing! 🎉

gr2m pushed a commit that referenced this pull request Sep 4, 2019
Fixes: #1670

Copies over the existing types and tests from DefinitelyTyped.
Includes updates to bring them up to date with 11.0

Remove `getTotalDelay` and `shouldPersist`, as they're considered private.
gr2m pushed a commit that referenced this pull request Sep 4, 2019
Fixes: #1670

Copies over the existing types and tests from DefinitelyTyped.
Includes updates to bring them up to date with 11.0

Remove `getTotalDelay` and `shouldPersist`, as they're considered private.
gr2m pushed a commit that referenced this pull request Sep 5, 2019
Fixes: #1670

Copies over the existing types and tests from DefinitelyTyped.
Includes updates to bring them up to date with 11.0

Remove `getTotalDelay` and `shouldPersist`, as they're considered private.
@mastermatt mastermatt added the TypeScript Anything related to TypeScript label Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released TypeScript Anything related to TypeScript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants