published TypeScript definitions incompatible with @types/nock
See original GitHub issueWhat 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:
- Created 4 years ago
- Comments:5 (4 by maintainers)
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.🎉 This issue has been resolved in version 11.3.2 🎉
The release is available on:
Your semantic-release bot 📦🚀