Skip to content

Typescript definitions not valid #737

@CageFox

Description

@CageFox

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.ts:

import * as protobuf from "protobufjs";
console.log("a");

  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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions