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

Using Custom Types with Repeated Keyword Doesn't Work #24

Closed
flolu opened this issue Oct 1, 2020 · 6 comments
Closed

Using Custom Types with Repeated Keyword Doesn't Work #24

flolu opened this issue Oct 1, 2020 · 6 comments

Comments

@flolu
Copy link
Contributor

flolu commented Oct 1, 2020

Building this proto file

syntax = "proto3";

message Car {
  string name = 1;
  string color = 2;
}

// custom repeated type throws error
message Cars {
  repeated Car cars = 1;
}

// primitve type works fine
message List {
  repeated string list = 1;
}

throws

/node_modules/typescript/lib/typescript.js:11851
        return array.hasOwnProperty("pos") && array.hasOwnProperty("end");
                     ^

TypeError: Cannot read property 'hasOwnProperty' of null
    at Object.isNodeArray (/node_modules/typescript/lib/typescript.js:11851:22)
    at createNodeArray (/node_modules/typescript/lib/typescript.js:20082:25)
    at Object.createCallExpression (/node_modules/typescript/lib/typescript.js:21335:95)
    at Object.createCall (/node_modules/typescript/lib/typescript.js:2814:29)
    at createToObject (/node_modules/protoc-gen-ts/index.js:49:14)
    at createMessage (/node_modules/protoc-gen-ts/index.js:1016:5)
    at processMessageDescriptor (/node_modules/protoc-gen-ts/index.js:1545:5)
    at processProtoDescriptor (/node_modules/protoc-gen-ts/index.js:1590:12)
    at main (/node_modules/protoc-gen-ts/index.js:1680:24)
    at Object.<anonymous> (/node_modules/protoc-gen-ts/index.js:1765:1)

I've created a repro here: https://github.com/flolu/protoc-gen-ts-repeated-repro

Basically it seems as if custom Types (in this case Car) doesn't work with the repeated keyword.

@flolu
Copy link
Contributor Author

flolu commented Oct 1, 2020

I think this is really weird considering, that there is a test exactly for this: https://github.com/thesayyn/protoc-gen-ts/blob/master/test/integration/messagefields.spec.ts

Do you have any ideas what might be the problem here?

@thesayyn
Copy link
Owner

thesayyn commented Oct 1, 2020

Looks like it fails while generating the typescript files. It could be easily traced IMHO. I'll take look at it in a few hours after work.

@JoowonYun
Copy link

I had the same problem. It seems you need to check the build package deploy in npm. When I built and generated locally, I could use it without any problem.

@davendu
Copy link

davendu commented Dec 17, 2020

I had the same problem. It seems you need to check the build package deploy in npm. When I built and generated locally, I could use it without any problem.

Could reproduce under same condition. Maybe need to check NPM released package.

@thesayyn
Copy link
Owner

I had no time to work on this. Any help is appreciated.

I'll try my best to fix this though.

@thesayyn
Copy link
Owner

Thanks to @dreamershl. A fix (#34) landed for this on master which will be released quickly.

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

4 participants