Skip to content

Protobuf .d.ts file overwritten at compile time?Β #23

@jbrjake

Description

@jbrjake

I noticed that I couldn't compile a TypeScript project which depended on sketch-js, because it couldn't find interfaces exported by the proto:

node_modules/@datadog/sketches-js/dist/ddsketch/mapping/CubicallyInterpolatedMapping.d.ts:2:10 - error TS2305: Module '"../proto/compiled"' has no exported member 'IndexMapping'.

Looking in the node_modules of my project, I noticed that @datadog/sketches-js/dist/ddsketch/proto/compiled.d.ts contained only the lines:

export = $root;
declare var $root: $protobuf.Root;
import $protobuf = require("protobufjs/minimal");

...instead of the rich types you provide in that file in this git repo.

This looks similar to an issue in another project, which I found when googling the error message I was seeing:
https://github.com/cryptowatch/cw-sdk-node/issues/31

The problem is that tsc, when generating declarations, overrides the existing compiled.d.ts file in its zeal to declare types for compiled.js.

When I simply paste the real file into my node_modules, I'm able to successfully build my dependent project.

I looked for ways to avoid generating declarations for only one file, but couldn't find an option like that in tsc.

I believe this should be resolvable by appending a copy to the build script in package.json:

    "build": "yarn clean; tsc -p tsconfig.build.json; cp src/ddsketch/proto/compiled.d.ts dist/ddsketch/proto/compiled.d.ts",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions