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

"Type error: Type 'k' cannot be used to index type" with skipLibCheck: false #53

Open
elliottsj opened this issue May 6, 2023 · 2 comments

Comments

@elliottsj
Copy link

Unsure if this is a zod issue or a t3-env issue.

Check out latest commit bfa7645

pnpm install
pnpm build
pnpm build --filter=@examples/nextjs
# observe build passes

Change examples/nextjs/tsconfig.json: set "skipLibCheck": false.

pnpm build --filter=@examples/nextjs
@examples/nextjs:build: ../../packages/nextjs/dist/index.d.ts:28:371
@examples/nextjs:build: Type error: Type 'k' cannot be used to index type 'addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }>'.
@examples/nextjs:build:
@examples/nextjs:build:   26 |     runtimeEnv: StrictOptions<ClientPrefix, TServer, TClient>["runtimeEnvStrict"];
@examples/nextjs:build:   27 | }
@examples/nextjs:build: > 28 | declare function createEnv<TServer extends Record<string, ZodType> = NonNullable<unknown>, TClient extends Record<`${ClientPrefix}${string}`, ZodType> = NonNullable<unknown>>({ runtimeEnv, ...opts }: Options<TServer, TClient>): (zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }> extends infer T_3 extends object ? { [k in keyof T_3]: zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }>[k]; } : never) & (zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }> extends infer T_4 extends object ? { [k_1 in keyof T_4]: zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }>[k_1]; } : never) extends infer T ? { [P in keyof T]: ((zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }> extends infer T_1 extends object ? { [k in keyof T_1]: zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }>[k]; } : never) & (zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }> extends infer T_2 extends object ? { [k_1 in keyof T_2]: zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }>[k_1]; } : never))[P]; } : never;
@examples/nextjs:build:      |                                                                                                                                                                                                                                                                                                                                                                                   ^
@examples/nextjs:build:   29 |
@examples/nextjs:build:   30 | export { createEnv };
@examples/nextjs:build:   31 |
@examples/nextjs:build:  ELIFECYCLE  Command failed with exit code 1.
@juliusmarminge
Copy link
Member

not sure 🤔

PS: why would you want skipLibCheck: false?

@elliottsj
Copy link
Author

PS: why would you want skipLibCheck: false?

To guard against library type errors bubbling up into application run time errors.

For example:

// index.ts
import MyType, { fn } from 'some-module';

const value: MyType = 'test';
fn(value);
// node_modules/some-module/index.d.ts

export type MyType = A; // A is not declared
export function fn(value: MyType): void;

With skipLibCheck: false, we get a type error: Type error: Cannot find name 'A'.

With skipLibCheck: true, there's no type error, so calling fn(value); will likely result in a run time error.

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