timostamm / protobuf-ts

Protobuf and RPC for TypeScript
Apache License 2.0
1.1k stars 129 forks source link

Global `Object` is not referenced when there is a message named Object. #610

Closed lesomnus closed 11 months ago

lesomnus commented 12 months ago

I compiled Argo Workflows v1alpha1 messages and there is a message named 'Object', which causes this issue:

Property 'keys' does not exist on type 'Object$Type'.ts(2339)

in the generated code:

...
        /* map<string, github.com.argoproj.argo_workflows.v3.pkg.apis.workflow.v1alpha1.Artifact> artifacts = 2; */
        for (let k of Object.keys(message.artifacts)) {  // <- HERE
            writer.tag(2, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k);
            writer.tag(2, WireType.LengthDelimited).fork();
...

I think it should be:

        for (let k of Object.keys(message.artifacts)) {
-        for (let k of Object.keys(message.artifacts)) {
+        for (let k of globalThis.Object.keys(message.artifacts)) {
            writer.tag(2, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k);
            writer.tag(2, WireType.LengthDelimited).fork();

I don't know this is related with the #579

timostamm commented 12 months ago

I think this might be a different issue than https://github.com/timostamm/protobuf-ts/issues/579. You are generating speed-optimized code, and it looks like it's missing a globalThis. This should be an easy fix, PRs welcome.

lesomnus commented 11 months ago

@timostamm Please review #611