Skip to content
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

Incorrect generation of TypeScript from es6 modules #686

Closed
nikitaulshin opened this issue Feb 22, 2017 · 3 comments
Closed

Incorrect generation of TypeScript from es6 modules #686

nikitaulshin opened this issue Feb 22, 2017 · 3 comments

Comments

@nikitaulshin
Copy link

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!

@dcodeIO
Copy link
Member

dcodeIO commented Feb 22, 2017

Hmm, does it work with the -n option (wraps everything in a module)?

pbts -n $FILENAME ../typescript/src/$FILENAME.js > ../typescript/src/$FILENAME.d.ts

The general issue could be that es6 modules export everything as default, where export * from might not work.

@nikitaulshin
Copy link
Author

I think export is the issue. But I don't get how to use the TS compiler with the es6 modules.
-n option did not solve the problem.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 22, 2017

Should be fixed in master. Feel free to reopen if there are any remaining issues.

@dcodeIO dcodeIO closed this as completed Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants