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

Type mismatch for RequestHeaderMatcher #2236

Open
davidlj95 opened this issue Oct 25, 2021 · 1 comment
Open

Type mismatch for RequestHeaderMatcher #2236

davidlj95 opened this issue Oct 25, 2021 · 1 comment
Labels
bug pull request welcome TypeScript Anything related to TypeScript

Comments

@davidlj95
Copy link

What is the expected behavior?
Definition of types for RequestHeaderMatcher is as this:

  type RequestHeaderMatcher =
    | string
    | RegExp
    | { (fieldValue: string): boolean }

Specifically, for the last one { (fieldValue: string): boolean }, seems when debugging that it's not the proper type.

What is the actual behavior?
When using matchHeader(name: string, value: RequestHeaderMatcher): this, and using a function in there as RequestHeaderMatcher, the fieldValue is not a string, but a string[]

If only one header is set for that name, we just receive 1 item in the array.

image
image

Possible solution
Update types for RequestHeaderMatcher, so that the fieldValue is actually a string[] as checked whilst debugging.

  type RequestHeaderMatcher =
    | string
    | RegExp
    | { (fieldValue: string[]): boolean }

However, unsure if rest of references to it (found 3 more) behave the same.

How to reproduce the issue
In a project with Typescript, use matchHeader to intercept a request, and use a function as RequestHeaderMatcher. You'll receive a string[] instead of a string as types say.

Runkit: Example link

Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.

Does the bug have a test case?
Nope! Not sure how to add something in https://github.com/nock/nock/blob/v13.1.4/types/tests.ts ! Though can try if have some time

Versions

Software Version(s)
Nock Detected on 13.1.4
Node Any
TypeScript Any
@gr2m gr2m added the TypeScript Anything related to TypeScript label Nov 8, 2021
@gr2m
Copy link
Member

gr2m commented Nov 8, 2021

We would appreciate a pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug pull request welcome TypeScript Anything related to TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants