grpc-node: @grpc/grpc-js is incompatible with typescript definations @types/node@17.0.6
Problem description
when project already has the dependency @types/node@17.0.6
, tsc
failed to build
Reproduction steps
yarn add @types/node@17.0.6 && tsc -b
- failed with output:
node_modules/@grpc/grpc-js/build/src/object-stream.d.ts:11:18` - error TS2430: Interface 'IntermediateObjectWritable<T>' incorrectly extends interface 'Writable'.
The types returned by 'end(...)' are incompatible between these types.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
11 export interface IntermediateObjectWritable<T> extends Writable {
~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@grpc/grpc-js/build/src/server-call.d.ts:64:5 - error TS2416: Property 'end' in type 'ServerWritableStreamImpl<RequestType, ResponseType>' is not assignable to the same property in base type 'Writable'.
Type '(metadata?: any) => void' is not assignable to type '{ (cb?: () => void): this; (chunk: any, cb?: () => void): this; (chunk: any, encoding: BufferEncoding, cb?: () => void): this; }'.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
64 end(metadata?: any): void;
~~~
node_modules/@grpc/grpc-js/build/src/server-call.d.ts:77:5 - error TS2416: Property 'end' in type 'ServerDuplexStreamImpl<RequestType, ResponseType>' is not assignable to the same property in base type 'Duplex'.
Type '(metadata?: any) => void' is not assignable to type '{ (cb?: () => void): this; (chunk: any, cb?: () => void): this; (chunk: any, encoding?: BufferEncoding, cb?: () => void): this; }'.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
77 end(metadata?: any): void;
~~~
Found 3 errors.
yarn add @types/node@17.0.5 && tsc -b
- successfully built again.
Environment
- OS name, version and architecture: M1 Pro, Macbook Pro
- Node version: 16.13.0
- Node installation method: brew
- Package name and version:
"@grpc/grpc-js": "^1.4.5"
tsconfig.json
{ "compilerOptions": { "lib": [ "ES2021" ], "module": "commonjs", "moduleResolution": "node", "target": "ES2021", "esModuleInterop": true, "allowSyntheticDefaultImports": true, "outDir": "dist" }, "include": [ "src/**/*" ], "exclude": [ "node_modules", "**/*.spec.ts" ] }
It seems that the version of dependency package @types/node
should be limited, rather than current “>=12.12.47”.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 33
- Comments: 23 (2 by maintainers)
Thank you for your patience with this error. I have published
@grpc/grpc-js
version 1.4.6 with a fix for it. Please update your dependencies to use the new version.@dancamdev Just change
@types/node
version inpackage.json
to this:Then:
It seems like
@types/node
definition was changed. Using"@types/node": "14.18.3"
build works fine.if it helps, enable
skipLibCheck
in yourtsconfig.json
to build project until this issue resolved.thankx this solved my problem but used
"@types/node": "17.0.5"
another version@johnnyoshika Fixed that, thank you!
@murgatroid99 sorry to ping you, but this issue has traction - seems to be affecting a lot of user