Skip to content

TS2416 when using @types/node < 14.0.19 #1350

@proton-ab

Description

@proton-ab

Describe the bug

  • Node.js version: v12.18.2
  • OS & version: node:12-alpine

Attempting to execute tsc on project using got == 11.5.0 results in TS2416 from got source code. Using @types/node v14.0.19 solves the issue but I should not be forced to use types for newer Node version that I use (that might result in runtime errors when using features not present in Node v12 but visible in types for v14)

"engines": {
  "node": ">=12.10.0"
},
"dependencies": {
  "got": "11.5.0"
},
"devDependencies": {
  "@types/node": "12.12.48"
}

Actual behavior

+ yarn --frozen-lockfile --non-interactive
yarn install v1.22.4
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
[5/5] Building fresh packages...
Done in 41.66s.
+ yarn lint
yarn run v1.22.4
$ run-p --aggregate-output --continue-on-error lint:*
$ prettier --check 'src/**/*.ts'
Checking formatting...
All matched files use Prettier code style!
$ eslint --ext .ts --format unix src/
Done in 9.12s.
+ yarn build
yarn run v1.22.4
$ rm -rf dist/ && tsc
node_modules/got/dist/source/core/index.d.ts(299,5): error TS2416: Property '_write' in type 'Request' is not assignable to the same property in base type 'Duplex'.
  Type '(chunk: any, encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, callback: (error?: ErrnoException | null | undefined) => void) => void' is not assignable to type '(chunk: any, encoding: string, callback: (error?: Error | null | undefined) => void) => void'.
    Types of parameters 'encoding' and 'encoding' are incompatible.
      Type 'string' is not assignable to type '"utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior

No build errors

Code to reproduce

https://github.com/proton-ab/kana/pull/1

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalThe issue related to an external projecttypesThe issue is related to TypeScript✭ help wanted ✭

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions