question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

published TypeScript definitions incompatible with @types/nock

See original GitHub issue

What is the expected behavior?

Nock TypeScript definitions should work similarly to how they behaved prior to types being introduced.

What is the actual behavior?

Prior to nock publishing TypeScript definitions, I was using the library with @types/nock instanced, and importing the module like so:

import * as nock from 'nock'

With the new types I receive this exception importing:

test/github.ts:24:6 - error TS2339: Property 'disableNetConnect' does not exist on type 'typeof import("/usr/local/google/home/bencoe/google/github-repo-automation/node_modules/nock/types/index")'.

24 nock.disableNetConnect();

If I switch to the following syntax, as recommended in #1684:

import nock from 'nock'

I instead receive the following exception:

nock.disableNetConnect();
     ^
TypeError: Cannot read property 'disableNetConnect' of undefined
    at Object.<anonymous> (/usr/local/google/home/bencoe/google/github-repo-automation/test/github.ts:24:6)
    at Module._compile (internal/modules/cjs/loader.js:868:30)

How to reproduce the issue

My typescript configuration is as follows:

{
  "extends": "./node_modules/gts/tsconfig-google.json",
  "compilerOptions": {
    "target": "es2015",
    "rootDir": ".",
    "outDir": "build"
  },
  "include": [
    "src/*.ts",
    "src/**/*.ts",
    "test/*.ts",
    "system-test/*.ts"
  ]
}

where tsconfig-google.json is equal to:

{
  "compilerOptions": {
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "declaration": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2016"],
    "module": "commonjs",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "pretty": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "exclude": [
    "node_modules"
  ]
}

I believe perhaps the root cause is an incompatibility with the types, as defined, and the commonjs module setting in TypeScript, unfortunately this is a standard configuration we’re currently using across dozens of repos.

Versions

Software Version(s)
Nock 11.3.1
Node v12.8.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Aug 23, 2019

Let me dig around and do some testing. I’ve mostly been using the types in DT on projects with esModuleInterop enabled.

If we can get away with supporting both import styles by using the export = approach while bundling, I’ll open a PR.

0reactions
nockbotcommented, Aug 23, 2019

🎉 This issue has been resolved in version 11.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Publishing - TypeScript
If your types are generated by your source code, publish the types with your source code. Both TypeScript and JavaScript projects can generate...
Read more >
Typescript Typings: The Complete Guide: @types Compiler ...
Typescript Typings - The Complete Guide To Type Definitions: @types, Compiler Opt-In Types: When To Use Each and Why?
Read more >
How do I write a Typescript definition file for a JavaScript ...
Types of property 'values' are incompatible. Type 'SVGAnimatedNumberList' is not assignable to type 'string[]'. node_modules/typescript/lib/lib.
Read more >
@types/node - npm
TypeScript definitions for Node.js. Latest version: 18.11.18, last published: 2 days ago. Start using @types/node in your project by running ...
Read more >
Surviving the TypeScript Ecosystem — Part 4 - Medium
If you are trying to use a JavaScript library in your TypeScript code there is a very good chance someone else has already...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found