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

Cannot find name 'I'. - when passing opts: --ts_proto_opt="outputServices=generic-definitions,outputServices=default" #939

Open
ws-gregm opened this issue Oct 4, 2023 · 7 comments

Comments

@ws-gregm
Copy link

ws-gregm commented Oct 4, 2023

@ws-gregm ➜ /workspaces/tools-workspaces/grpc-poc-server (staging) $ yarn build
yarn run v1.22.19
$ rm -rf dist && tsc
node_modules/@wingspanhq/proto-poc/dist/ts-proto-generated/proto/index.d.ts:105:43 - error TS2304: Cannot find name 'I'.

105                 } & { [K in Exclude<keyof I, "result">]: never; }>(base?: I_2): IHelloResponse;
                                              ~

node_modules/@wingspanhq/proto-poc/dist/ts-proto-generated/proto/index.d.ts:110:45 - error TS2304: Cannot find name 'I_1'.

110                 } & { [K_1 in Exclude<keyof I_1, "result">]: never; }>(object: I_3): IHelloResponse;
                                                ~~~

node_modules/@wingspanhq/proto-poc/dist/ts-proto-generated/proto/index.d.ts:154:43 - error TS2304: Cannot find name 'I'.

154                 } & { [K in Exclude<keyof I, "count">]: never; }>(base?: I_2): ICountPendingEventsResponse;
                                              ~

node_modules/@wingspanhq/proto-poc/dist/ts-proto-generated/proto/index.d.ts:159:45 - error TS2304: Cannot find name 'I_1'.

159                 } & { [K_1 in Exclude<keyof I_1, "count">]: never; }>(object: I_3): ICountPendingEventsResponse;
                                                ~~~
@stephenh
Copy link
Owner

stephenh commented Oct 4, 2023

I don't really recognize the output here; it looks like:

export type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

But we don't output keyof I, "result", we output keyof I, KeysOfUnion....

We also don't output keyof I_1 with the _1 suffix...

Can you include more than just a single line of context?

You've also linked to compile errors in index.d.ts files, but ts-proto generates *.ts files.

My guess is that the code in the ts-proto-generated *.ts files is fine, but something is happening on the compilation to index.d.ts, that is likely specific to your build process.

@ws-gregm
Copy link
Author

ws-gregm commented Oct 6, 2023

I'm just running tsc. Here is what my tsconfig.json looks like...

$ cat tsconfig.json 
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./dist",
    "types": ["node", "@types/long"]
  },
  "exclude": ["node_modules", "dist"],
  "include": ["src/**/*"]
}

@ws-gregm
Copy link
Author

ws-gregm commented Oct 9, 2023

@stephenh Any idea here? Otherwise, I might resort to outputServices=grpc-js which works as intended but then, I would have to change a bunch of code to match the different casing of method names.

@stephenh
Copy link
Owner

No, no ideas. From the title, you're passing

opts: --ts_proto_opt="outputServices=generic-definitions,outputServices=default

I think the syntax would be "outputServices=generic-definitions,default" instead of repeating outputServices again, but not sure how that'd led to your compile error.

@talgendler
Copy link

Hi @stephenh I have the same problem.
When I generate the code it look like this: (relevant parts only)

create<I extends Exact<DeepPartial<VerdictResponse>, I>>(base?: I): VerdictResponse {
  return VerdictResponse.fromPartial(base ?? ({} as any));
}

but when I run tsc the output is broken:

create<I_2 extends {
                    data?: {
                        message?: string | undefined;
                        code?: string | undefined;
                    } | undefined;
                    error?: {
                        code?: string | undefined;
                        message?: string | undefined;
                        path?: string | undefined;
                        extra?: {
                            [x: string]: any;
                        } | undefined;
                    } | undefined;
                } & {
                    data?: ({
                        message?: string | undefined;
                        code?: string | undefined;
                    } & {
                        message?: string | undefined;
                        code?: string | undefined;
                    } & { [K in Exclude<keyof I["data"], keyof HttpSuccess>]: never; }) | undefined;
                    error?: ({
                        code?: string | undefined;
                        message?: string | undefined;
                        path?: string | undefined;
                        extra?: {
                            [x: string]: any;
                        } | undefined;
                    } & {
                        code?: string | undefined;
                        message?: string | undefined;
                        path?: string | undefined;
                        extra?: ({
                            [x: string]: any;
                        } & {
                            [x: string]: any;
                        } & { [K_1 in Exclude<keyof I["error"]["extra"], string | number>]: never; }) | undefined;
                    } & { [K_2 in Exclude<keyof I["error"], keyof HttpError>]: never; }) | undefined;
                } & { [K_3 in Exclude<keyof I, keyof VerdictResponse>]: never; }>(base?: I_2 | undefined): VerdictResponse;

errors:

Cannot find name 'I'.

193                     } & { [K in Exclude<keyof I["data"], keyof HttpSuccess>]: never; }) | undefined;
                                                  ~
 Cannot find name 'I'.

209                         } & { [K_1 in Exclude<keyof I["error"]["extra"], string | number>]: never; }) | undefined;
                                                        ~

@stephenh
Copy link
Owner

Hi @talgendler ; I still don't know why tsc is changing the output like that; maybe there is a tsconfig option you have enabled that is modifying the *.d.ts file for backwards compatibility or something? What version of tsc are you using?

You should be able to disable the exact types, and that will avoid the Exact<...> wrapper, which will hopefully result in tsc not transforming the *.d.ts output like that.

@talgendler
Copy link

@stephenh Thank you for your reply, I'm using tsc version 5.3.3 but this was reproduced in 4.9.5 as well. I'm puzzled as you and honestly have no idea what causes it.
I'll take a look at our tsconfig.json and if I find something will update here.

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

3 participants