Skip to content

Unable to infer an interface for DataMatcher definition #1708

@JrSchild

Description

@JrSchild

What is the expected behavior?

The following example should compile:

import * as nock from 'nock';

interface Body {
  param: number;
}

const body: Body = {
  param: 1,
};

const scope = nock('http://example.test')
  .post('/users', body)
  .reply(200);

What is the actual behavior?
Typescript does not allow this, because it can not infer an interface as a dictionary.
({ [k: string]: ... }) if it is not explicitly intended as one. More on this issue here microsoft/TypeScript#15300 and here.

The following error is thrown upon compilation:

Argument of type 'Body' is not assignable to parameter of type 'string | RegExp | Buffer | DataMatcher | ((body: any) => boolean) | undefined'.
  Type 'Body' is not assignable to type 'DataMatcher'.
    Index signature is missing in type 'Body'.

Possible solution

How to reproduce the issue
The latest typescript definitions are not yet released which are required for this to reproduce. The example above can be run instead.

Does the bug have a test case?

Versions

Software Version(s)
Nock master
Node 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptAnything related to TypeScriptstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions