Skip to content

Incorrect generation of TypeScript from es6 modules #686

@nikitaulshin

Description

@nikitaulshin

protobuf.js version: <6.6.3>

Hello.
Thanks for your library!
Unfortunately I found out that es6 modules are compiled into TypeScript typings incorrectly.
I have multiple export statements in the ts file while js file has single default export.

Let's say I have following .proto:

syntax = "proto3";

message ExceptionModelItem {
    string text = 1;
    double value = 2;

    enum ExceptionStatus {
        ERROR = 0;
        WARNING = 1;
        OK = 2;
    }

    ExceptionStatus  status = 3;
}

message ExceptionModelItemList {
    repeated ExceptionModelItem items = 1;
}

message ExceptionModel {
    repeated ExceptionModelItemList items = 1;
}

And I have following generation code:

#!/usr/bin/env bash

ARRAY=()
for item in $( ls *.proto); do
    FILENAME=${item%.*}
    echo $FILENAME
    ARRAY+=("export * from './"$FILENAME"';")
    pbjs -t static-module -w es6 -o ../typescript/src/$FILENAME.js $item
    pbts ../typescript/src/$FILENAME.js > ../typescript/src/$FILENAME.d.ts
done

printf "%s\n" "${ARRAY[@]}" > ../typescript/src/index.ts

When I try to use the code above, es6 modules doesn't work. But if you try to use common js, the result works just perfect.

Thanks!

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