Compilation errors in `Schema.d.ts` file
🐛 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.
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)
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.
Upgrading to latest deps (https://github.com/Effect-TS/schema/pull/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" />
~~~~
@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.
@stazz I'm using latest /schema (0.10.0)