ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

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

Open ws-gregm opened this issue 2 years ago • 7 comments

@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;
                                                ~~~

ws-gregm avatar Oct 04 '23 12:10 ws-gregm

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.

stephenh avatar Oct 04 '23 17:10 stephenh

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 avatar Oct 06 '23 20:10 ws-gregm

@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.

ws-gregm avatar Oct 09 '23 17:10 ws-gregm

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.

stephenh avatar Oct 10 '23 03:10 stephenh

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;
                                                        ~

talgendler avatar Jan 16 '24 14:01 talgendler

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.

stephenh avatar Jan 28 '24 16:01 stephenh

@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.

talgendler avatar Jan 29 '24 11:01 talgendler