Skip to content

typescript definitions meta-issue #718

@tamird

Description

@tamird

protobuf.js version: 6.6.5

First, thank you for including typescript support! I was delighted to discover that I could stop using https://github.com/sintef-9012/Proto2TypeScript.

However, there are a few problems with the generated and bundled TS definitions:

  • The included interface Long makes it impossible to chain Long methods on fields; e.g. d.timestampNanos.toNumber() becomes d.timestampNanos as Long).toNumber()
  • The generated type of certain numeric fields is number|Long, which also makes it impossible to chain Long methods; i.e. it becomes necessary to coalesce or cast to Long before being able to use the field value.
  • The bundled type definitions include hard-coded references to Buffer, which is only available in Node.js. In CockroachDB we are using protobuf.js in the browser, and would like to avoid including type definitions for Node.js types which will not be available at run time.
  • The generated definitions should also include interfaces from which protobuf objects can be constructed (distinct from the protobuf objects themselves). This is partially related to Which JS types are valid in fromObject, create, and encode? #719.

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