New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript definitions inconsistent #503

Closed
endel opened this Issue Nov 30, 2016 · 10 comments

Comments

Projects
None yet
2 participants
@endel
Contributor

endel commented Nov 30, 2016

Hey there,

I've tried to use v6.0.0 with TypeScript and unfortunately some of the definitions are inconsistent :(

Here's the errors I'm having:

node_modules/protobufjs/types/protobuf.js.d.ts(1138,10): error TS2415: Class 'BufferReader' incorrectly extends base class 'Reader'.
  Types of property 'finish' are incompatible.
    Type '(buffer?: Buffer) => Buffer' is not assignable to type '(buffer?: number[]) => number[]'.
      Types of parameters 'buffer' and 'buffer' are incompatible.
        Type 'number[]' is not assignable to type 'Buffer'.
          Property 'write' is missing in type 'number[]'.
node_modules/protobufjs/types/protobuf.js.d.ts(1792,61): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
node_modules/protobufjs/types/protobuf.js.d.ts(2050,10): error TS2415: Class 'BufferWriter' incorrectly extends base class 'Writer'.
  Types of property 'float' are incompatible.
    Type '(value: number) => BufferWriter' is not assignable to type '(value: number) => Writer'.
      Type 'BufferWriter' is not assignable to type 'Writer'.
        Types of property 'bytes' are incompatible.
          Type '(value: Buffer) => BufferWriter' is not assignable to type '(value: number[]) => Writer'.
            Types of parameters 'value' and 'value' are incompatible.
              Type 'number[]' is not assignable to type 'Buffer'.
src/index.ts(2,27): error TS2306: File 'xxx/node_modules/protobufjs/types/protobuf.js.d.ts' is not a module.

Cheers!

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Nov 30, 2016

Thanks, I somewhat expected some issues with the automatically generated tsds. Will see what I can do!

dcodeIO added a commit that referenced this issue Nov 30, 2016

dcodeIO added a commit that referenced this issue Nov 30, 2016

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Nov 30, 2016

This is now pulling long.js and node.js definitions post install (mostly for me to see the errors you described) and uses Uint8Array to reference any kind of buffer, which should be consistent enough for node.js as buffers are Uint8Arrays nowadays. Let me know what's working and what's not!

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 1, 2016

Feel free to reopen if there are still any issues.

@dcodeIO dcodeIO closed this Dec 1, 2016

@endel

This comment has been minimized.

Contributor

endel commented Dec 2, 2016

Hey, thanks @dcodeIO. It solved the mismatching types issue, but there's still errors happening. I've created a repository that makes it easy to reproduce the problem here: https://github.com/endel/protobufjs-tsc-error/

$ tsc
index.ts(1,27): error TS2306: File '/Users/edreyer/Projects/protobufjs-tsc/node_modules/protobufjs/types/protobuf.js.d.ts' is not a module.
node_modules/protobufjs/types/protobuf.js.d.ts(1,1): error TS6053: File '/Users/edreyer/Projects/protobufjs-tsc/node_modules/protobufjs/node_modules/@types/node/index.d.ts' not found.
node_modules/protobufjs/types/protobuf.js.d.ts(2,1): error TS6053: File '/Users/edreyer/Projects/protobufjs-tsc/node_modules/protobufjs/node_modules/@types/long/index.d.ts' not found.

Cheers!

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 2, 2016

Does it work when you change the references at the top to

/// <reference types="node" />
/// <reference types="long" />

?

dcodeIO added a commit that referenced this issue Dec 2, 2016

@endel

This comment has been minimized.

Contributor

endel commented Dec 2, 2016

@dcodeIO unfortunately not. Same thing. 😢

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 2, 2016

What happens when you explicitly add the following to your package's dependencies?

    "@types/long": "^3.0.31",
    "@types/node": "0.0.1",
@endel

This comment has been minimized.

Contributor

endel commented Dec 2, 2016

@endel

This comment has been minimized.

Contributor

endel commented Dec 2, 2016

Hey, @dcodeIO I've just tested with your recent fixes on master and the only error that still happens is:

index.ts(4,27): error TS2306: File '/Users/edreyer/Projects/protobuf.js/types/protobuf.js.d.ts' is not a module.

I could solve it by adding this line to the end of the protobuf.js.d.ts file:

export = protobuf;

Cheers!

@endel

This comment has been minimized.

Contributor

endel commented Dec 2, 2016

Actually, there are loads of other problems now that I'm finally able to require it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment