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

Compilation errors in Schema.d.ts file #1841

Closed
stazz opened this issue Apr 2, 2023 · 5 comments · Fixed by #2339 or #2338
Closed

Compilation errors in Schema.d.ts file #1841

stazz opened this issue Apr 2, 2023 · 5 comments · Fixed by #2339 or #2338
Labels

Comments

@stazz
Copy link

stazz commented Apr 2, 2023

🐛 Bug report

Current Behavior

Running tsc for any code using @effect/schema library version 0.9.0 results in the following error messages:

node_modules/@effect/schema/Schema.d.ts:273:324 - error TS2536: Type 'K_4' cannot be used to index type '{ readonly [K in Exclude<keyof Fields, OptionalKeys<Fields>>]: From<Fields[K]>; } & { readonly [K_1 in OptionalKeys<Fields>]?: From<Fields[K_1]>; }'.

273 export declare const struct: <Fields extends Record<PropertyKey, Schema<any, any> | OptionalSchema<any, any>>>(fields: Fields) => Schema<{ readonly [K in Exclude<keyof Fields, OptionalKeys<Fields>>]: From<Fields[K]>; } & { readonly [K_1 in OptionalKeys<Fields>]?: From<Fields[K_1]>; } extends infer T ? { [K_4 in keyof T]: ({ readonly [K in Exclude<keyof Fields, OptionalKeys<Fields>>]: From<Fields[K]>; } & { readonly [K_1 in OptionalKeys<Fields>]?: From<Fields[K_1]>; })[K_4]; } : never, { readonly [K_2 in Exclude<keyof Fields, OptionalKeys<Fields>>]: To<Fields[K_2]>; } & { readonly [K_3 in OptionalKeys<Fields>]?: To<Fields[K_3]>; } extends infer T_1 ? { [K_5 in keyof T_1]: ({ readonly [K_2 in Exclude<keyof Fields, OptionalKeys<Fields>>]: To<Fields[K_2]>; } & { readonly [K_3 in OptionalKeys<Fields>]?: To<Fields[K_3]>; })[K_5]; } : never>;

                                                                                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@effect/schema/Schema.d.ts:273:681 - error TS2536: Type 'K_5' cannot be used to index type '{ readonly [K_2 in Exclude<keyof Fields, OptionalKeys<Fields>>]: To<Fields[K_2]>; } & { readonly [K_3 in OptionalKeys<Fields>]?: To<Fields[K_3]>; }'.

273 export declare const struct: <Fields extends Record<PropertyKey, Schema<any, any> | OptionalSchema<any, any>>>(fields: Fields) => Schema<{ readonly [K in Exclude<keyof Fields, OptionalKeys<Fields>>]: From<Fields[K]>; } & { readonly [K_1 in OptionalKeys<Fields>]?: From<Fields[K_1]>; } extends infer T ? { [K_4 in keyof T]: ({ readonly [K in Exclude<keyof Fields, OptionalKeys<Fields>>]: From<Fields[K]>; } & { readonly [K_1 in OptionalKeys<Fields>]?: From<Fields[K_1]>; })[K_4]; } : never, { readonly [K_2 in Exclude<keyof Fields, OptionalKeys<Fields>>]: To<Fields[K_2]>; } & { readonly [K_3 in OptionalKeys<Fields>]?: To<Fields[K_3]>; } extends infer T_1 ? { [K_5 in keyof T_1]: ({ readonly [K_2 in Exclude<keyof Fields, OptionalKeys<Fields>>]: To<Fields[K_2]>; } & { readonly [K_3 in OptionalKeys<Fields>]?: To<Fields[K_3]>; })[K_5]; } : never>;



                                                                                                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@effect/schema/Schema.d.ts:433:245 - error TS2536: Type 'K_1' cannot be used to index type 'A & { readonly [k in K]: V; }'.

433 export declare const attachPropertySignature: <K extends PropertyKey, V extends AST.LiteralValue>(key: K, value: V) => <I, A extends object>(schema: Schema<I, A>) => Schema<I, A & { readonly [k in K]: V; } extends infer T ? { [K_1 in keyof T]: (A & { readonly [k in K]: V; })[K_1]; } : never>;

                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 3 errors in the same file, starting at: node_modules/@effect/schema/Schema.d.ts:273

Expected behavior

Running tsc will not produce any errors.

Reproducible example

Any code which imports @effect/schema library version 0.9.0.

Suggested solution(s)

I again propose adding a step to your CI/CD pipeline, which would try to compile/transpile some small dummy code against the d.ts files produced by previous compilation/transpilation step.
That will add safeguard against these kind of errors for the future, at least for one TSC version.

Additional context

There luckily is workaround to add --skipLibCheck to tsc, so this bug is not a blocker.
Though, the workaround will then affect all .d.ts files, both own and all the libraries in node_modules.

Your environment

Software Version(s)
@effect/schema 0.9.0
TypeScript 5.0.2

I think I saw similar error also in 0.8.0.

@gcanti
Copy link
Contributor

gcanti commented Apr 3, 2023

Should be fixed in 0.9.1, though I still get the following from effect/io (cc @IMax153)

node_modules/@effect/io/Effect.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.

1 /// <reference types="node" />

(having an additional step in our CI pipeline would be nice indeed)

@stazz
Copy link
Author

stazz commented Apr 3, 2023

Thank you for quick solution! 👍 I can confirm things now compile without errors. I think that's because my project already has reference to @types/node.

I can take a look to see if I can create something for the CI step, in the following days.

@gcanti
Copy link
Contributor

gcanti commented Apr 3, 2023

Upgrading to latest deps (Effect-TS/schema#211) added a new error in my setup:

node_modules/@effect/data/Option.d.ts:49:18 - error TS2430: Interface 'Some<A>' incorrectly extends interface 'Effect<never, never, A>'.
  The types returned by 'traced(...)' are incompatible between these types.
    Type 'this | TracedOption<this["value"]>' is not assignable to type 'Effect<never, never, A>'.
      Type 'this' is not assignable to type 'Effect<never, never, A>'.
        Type 'Some<A>' is not assignable to type 'Effect<never, never, A>'.
          The types returned by 'traced(...)' are incompatible between these types.
            Type 'this | TracedOption<this["value"]>' is not assignable to type 'Effect<never, never, A>'.
              Type 'TracedOption<this["value"]>' is not assignable to type 'Effect<never, never, A>'.
                The types returned by '[EffectTypeId]._E(...)' are incompatible between these types.
                  Type 'NoSuchElementException' is not assignable to type 'never'.

49 export interface Some<A> extends Data.Case {
                    ~~~~

node_modules/@effect/io/Effect.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.

1 /// <reference types="node" />
                        ~~~~

@stazz
Copy link
Author

stazz commented Apr 3, 2023

@gcanti FWIW, my package.json looks like this:

{
  "dependencies": {
    "@effect/match": "0.10.1",
    ...
  },
  "resolutions": {
    "@effect/data": "0.10.2",
    "@effect/schema": "0.9.1",
    ...
  }

And TSC (5.0.2) completes successfully.

@gcanti
Copy link
Contributor

gcanti commented Apr 5, 2023

@stazz I'm using latest /schema (0.10.0)

@fubhy fubhy added the schema label Jan 1, 2024
@fubhy fubhy transferred this issue from Effect-TS/schema Jan 1, 2024
gcanti added a commit that referenced this issue Mar 15, 2024
…d `TaggedRequest` to avoid errors in `Schema.d.ts`, closes #1841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
3 participants