tatethurston / TwirpScript

A protobuf RPC framework for JavaScript and TypeScript
MIT License
141 stars 14 forks source link

Type error: `symbol` is not present in `IncomingMessage` #179

Closed AnatolyRugalev closed 2 years ago

AnatolyRugalev commented 2 years ago

I'm getting this type error when building my package:

node_modules/twirpscript/runtime/server/index.d.ts:24:52 - error TS2344: Type 'symbol | "headers" | "method" | "url"' does not satisfy the constraint 'keyof IncomingMessage'.
  Type 'symbol' is not assignable to type 'keyof IncomingMessage'.

Declaration of this type looks like this:

declare type ServerRequest = Pick<IncomingMessage, "method" | "url" | "headers" | typeof Symbol.asyncIterator>;

I dropped last part typeof Symbol.asyncIterator and it fixed the problem for me.

Thanks

tatethurston commented 2 years ago

Hey @AnatolyRugalev do you have a repo I could take a look at? If not, could you let me know the version of TypeScript you're using, and could you paste your tsconfig.json here?

AnatolyRugalev commented 2 years ago

@tatethurston I have to admit that I have no idea what I'm doing when it comes to the TypeScript. I am essentially working on API itself and I need JS compatible client for our testing framework. I will certainly provide you with everything I can, but please forgive me for my ignorance.

This is the repo that I use for twirp generation: https://github.com/GetStream/stream-chat-js/tree/twirp-api

The repo is set up for ES5 target in tsconfig.json, so I bumped it to ES2020 to fix other compilation errors. I also changed parser version in .eslintrc.json to 2020 which, I assume, corresponds to ES2020 build target.

You can find all changes that I did to make it work with TwirpScript in this commit: https://github.com/GetStream/stream-chat-js/commit/e66385e471c92633427df79fa4e91cbbe0acd3d3

tatethurston commented 2 years ago

Thanks @AnatolyRugalev. I’ll take a look and see if I can recreate the type error. Off the top of my head, it could be very old @types/node but I’ll let you know what I find. In theory, if you’re just building a client and not using the server then @node/types should be unnecessary — I’ll check and if that is not the case I’ll update twirpscript.

As a design goal, I would like TwirpScript to “just work” with any starter tsconfig, no Typescript knowledge required. This will help me provide some guidance for minimal supported versions for typescript and node.

tatethurston commented 2 years ago

This has been resolved in v0.0.60. Thanks @AnatolyRugalev!