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

Enabling "outputJsonMethods" and "outputPartialMethods" causes builds to fail. #459

Closed
stevevarga opened this issue Dec 29, 2021 · 3 comments

Comments

@stevevarga
Copy link

stevevarga commented Dec 29, 2021

Using TS-Proto v1.96.1 with the following config

ts_proto_opt=returnObservable=true,lowerCaseServiceMethods=true,esModuleInterop=true,useOptionals=none,outputJsonMethods=true,outputEncodeMethods=false,outputPartialMethods=true,exportCommonSymbols=true,outputClientImpl=false,oneof=unions

fails to compile, with a large number of issues.

Disabling outputPartialMethods causes fewer issues, but there are several issues that remain with google/protobuf/struct.ts. First, the struct 'fromJSON' method uses 'fromPartial', which is not being generated.

const struct = Struct.fromPartial({});

Second, the wrap method uses syntax that is incompatible with the oneof=unions syntax.

unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
    if (message?.stringValue !== undefined) {
      return message.stringValue;
    } else if (message?.numberValue !== undefined) {
      return message.numberValue;
    } else if (message?.boolValue !== undefined) {
      return message.boolValue;
    } else if (message?.structValue !== undefined) {
      return message.structValue;
    } else if (message?.listValue !== undefined) {
      return message.listValue;
    } else if (message?.nullValue !== undefined) {
      return null;
    }
    return undefined;
  },

Once outputPartialMethods is enabled, a large number of errors (~593 in my case) appear. They seem to be mostly related to Generics...

Property 'enabled' does not exist on type 'I'
Type 'I' does not satisfy the constraint
Type 'Record' is not generic.
etc.

Here is my TSConfig, for Typescript version 4.5.4

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": ["es2017", "dom"],
    "declaration": true,
    "outDir": "./lib",
    "strict": true,
    "esModuleInterop": true,
  },
  "include": [
    "./src"
  ],
  "exclude": [
    "node_modules",
    "**/__tests__/*"
  ]
}

Side note: Enabled outputPartialMethods without enabling outputJson seems to be a no-op.

@stevevarga stevevarga changed the title Enabling "outputJsonMethods" causes Enabling "outputJsonMethods" and "outputPartialMethods" causes builds to fail. Dec 29, 2021
@stevevarga
Copy link
Author

Update: This seems to be an issue introduced in 1.96.1.

Rolling back to 1.96.0 fixes compilation issues with the flags.

@stephenh
Copy link
Owner

stephenh commented Jan 1, 2022

Hm, well the the struct.ts / oneof=unions I think is a known issue in #458...

Property 'enabled' does not exist on type 'I'

Can you give more context of the code that causes that error?

You can try the newly added useExactTypes=false option to see if it fixes the generic errors, but if it does I'd love to have a as-minimal-as-possible reproduction *.proto that shows what the issue is, to see if we can try and fix it, instead of just disabling it.

@stevevarga
Copy link
Author

Confirmed duplicate of #458.

Can now no longer reproduce the generic issue, it may have been a side effect of #458 or TS config settings. Will open a new issue if it comes up again with a concrete example.

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