Grpc-node: Typescript compilation failing

Created on 12 Jul 2019  路  7Comments  路  Source: grpc/grpc-node

Problem description

Typescript compilation fails:

node_modules/@grpc/grpc-js/build/src/call-stream.d.ts:92:5 - error TS2416: Property '_write' in type 'Http2CallStream' is not assignable to the same property in base type 'Duplex'.
  Type '(chunk: WriteObject, encoding: string, cb: WriteCallback) => void' is not assignable to type '(chunk: any, encoding: string, callback: (err?: Error | undefined) => void) => void'.
    Types of parameters 'cb' and 'callback' are incompatible.
      Types of parameters 'err' and 'error' are incompatible.
        Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
          Type 'null' is not assignable to type 'Error | undefined'.

92     _write(chunk: WriteObject, encoding: string, cb: WriteCallback): void;

Reproduction steps

tsc

Environment

Additional context

N/A

Most helpful comment

As far as I can tell, fixes to @types/node don't really get backported to earlier versions much. So the latest version is also the most correct version. We use a very recent version because earlier ones are inconsistent with the real APIs in ways that impact us.

It's true that there is a conflict here between getting those fixes, and having types that match your Node version. I would suggest using the latest version of @types/node and consulting the Node 8 version of the API documentation. But it should work just fine. tsc doesn't actually generate any code based on the types files you use. It just uses them to verify what APIs you have access to.

All 7 comments

It looks like you have an old version of @types/node I suggest updating that package. I'll leave this issue open as a reminder to update our dependency on that package.

@murgatroid99 Thanks, I updated to the latest version "12.6.2", and it works. How come it's so sensitive to even fail on a @types/node version 3 months old? i.e., 11.13.4? I'm running node v11.12.0.

Also will the @node/types version 12 work with node 8? That's what is required to run in firebase functions. Although it's not clear to me if I can tsc with node 11, but then run using node 8?

As far as I can tell, fixes to @types/node don't really get backported to earlier versions much. So the latest version is also the most correct version. We use a very recent version because earlier ones are inconsistent with the real APIs in ways that impact us.

It's true that there is a conflict here between getting those fixes, and having types that match your Node version. I would suggest using the latest version of @types/node and consulting the Node 8 version of the API documentation. But it should work just fine. tsc doesn't actually generate any code based on the types files you use. It just uses them to verify what APIs you have access to.

It looks like we already did update that dependency. We can't really do anything about TypeScript messing up because our user depends on an earlier version of the same library and TypeScript prioritizes that.

@murgatroid99 Did you find a solution? We hit similar issue when installing @google-cloud/pubsub packages for firebase cloud functions. It just makes it unusable on node8. It would be great if someone has a solution.

The grpc library depends on the correct version of @types/node. If you depend on a different version of @types/node and it doesn't work, the solution is to not have that dependency.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wenxiwu777 picture wenxiwu777  路  4Comments

nhanpiti picture nhanpiti  路  3Comments

respinha picture respinha  路  6Comments

ozt88 picture ozt88  路  3Comments

tvk-codecraft picture tvk-codecraft  路  3Comments