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 not valid #737

CageFox opened this Issue Mar 31, 2017 · 6 comments


None yet
3 participants

CageFox commented Mar 31, 2017

protobuf.js version: 6.7.0

  1. Install typescript@next locally or globally:

npm i -g typescript@next

  1. Create empty dir for project, inside make one typescript file:

import * as protobuf from "protobufjs";

  1. Install protobufjs in above project directory:

npm install protobufjs

  1. Compile:
    tsc test.ts

Expected behaviour: compile success

Current behaviour: numerous typescript errors:

node_modules/protobufjs/index.d.ts(419,13): error TS2300: Duplicate identifier 'LoadCallback'.
node_modules/protobufjs/index.d.ts(425,6): error TS2300: Duplicate identifier 'LoadCallback'.
node_modules/protobufjs/index.d.ts(1103,13): error TS2300: Duplicate identifier 'ParserResult'.
node_modules/protobufjs/index.d.ts(1111,6): error TS2300: Duplicate identifier 'ParserResult'.
node_modules/protobufjs/index.d.ts(1115,13): error TS2300: Duplicate identifier 'ParseOptions'.
node_modules/protobufjs/index.d.ts(1119,6): error TS2300: Duplicate identifier 'ParseOptions'.
node_modules/protobufjs/index.d.ts(1520,40): error TS2694: Namespace '"C:/a/node_modules/protobufjs/index".rpc.rpc' has no exported member 'Service'.
node_modules/protobufjs/index.d.ts(1526,13): error TS2300: Duplicate identifier 'RPCImpl'.
node_modules/protobufjs/index.d.ts(1541,6): error TS2300: Duplicate identifier 'RPCImpl'.
node_modules/protobufjs/index.d.ts(1545,13): error TS2300: Duplicate identifier 'RPCImplCallback'.
node_modules/protobufjs/index.d.ts(1551,6): error TS2300: Duplicate identifier 'RPCImplCallback'.
node_modules/protobufjs/index.d.ts(1610,33): error TS2300: Duplicate identifier 'TokenizerHandle'.
node_modules/protobufjs/index.d.ts(1618,6): error TS2300: Duplicate identifier 'TokenizerHandle'.
node_modules/protobufjs/index.d.ts(1821,13): error TS2300: Duplicate identifier 'ConversionOptions'.
node_modules/protobufjs/index.d.ts(1836,11): error TS2300: Duplicate identifier 'ConversionOptions'.
node_modules/protobufjs/index.d.ts(2013,13): error TS2300: Duplicate identifier 'Long'.

Way to fix: rebuild protobufjs file index.d.ts by pbts but with added option --no-comments

Reason: Typescript using JSDoc data to build types info, but with JSDoc comments typescript use same types twice:


  • A node-style callback as used by {@link load} and {@link Root#load}.
  • @typedef LoadCallback
  • @type {function}
  • @param {?Error} error Error, if any, otherwise null
  • @param {Root} [root] Root, if there hasn't been an error
  • @returns {undefined}
    type LoadCallback = (error: Error, root?: Root) => void;

This comment has been minimized.


dcodeIO commented Mar 31, 2017

Imho, TypeScript shouldn't use JSDoc data from d.ts files at all, because these cannot even contain JavaScript technically. Not sure that this is a protobuf.js problem in the first place.

Of course we can fix this for now by excluding just @typedef comments. Iirc these do not result in any sort of IntelliSense documentation anyway.


This comment has been minimized.

CageFox commented Mar 31, 2017

Typescript is rather new and very swiftly evolving project, but right now use of protobufjs in typescript projects lead to above problem

Personally I agree with you and see no reason typescript using JSDoc data from d.ts, but that's current situation.

I also see no reason to keep JSDoc data in d.ts files, as JSDoc and d.ts both define type data

Will you fix the problem?


This comment has been minimized.


dcodeIO commented Mar 31, 2017

I also see no reason to keep JSDoc data in d.ts files

The idea here is to provide textual IntelliSense documentation right from the .d.ts file, even when using a .min.js file.

Will you fix the problem?


dcodeIO added a commit that referenced this issue Mar 31, 2017


This comment has been minimized.

hnfmr commented Apr 3, 2017

We are having the same issue, tsc complains about Long in the generated typings...
We locked protobufjs to 6.6.5 for now...


This comment has been minimized.


dcodeIO commented Apr 3, 2017

When not using long.js typings, just reference the stub somewhere in your project:

/// <reference path="./node_modules/protobufjs/stub-long.d.ts" />

See: Usage with TypeScript


This comment has been minimized.


dcodeIO commented Apr 11, 2017

6.7.3 includes typings for long and node again.

For reference, see these issues: #711 #753

So, this should be sorted in your favor now. Feel free to reopen if it is not!

@dcodeIO dcodeIO closed this Apr 11, 2017

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