TypeScript Schema Parsing Error: Incompatible Argument Types in Union
Why is this not allowed?
The error is the following over the "schema" token on the last line:
Note that
import { Schema as S } from "@effect/schema";
const D = S.TaggedStruct("D", { content: S.String, })
const A = S.suspend(() => S.Struct({ component: S.Union(B, C, D) }),)
const Fields: S.Struct.Fields = { children: S.Array(A), };
const C = S.TaggedStruct("C", Fields)
const B = S.TaggedStruct("B", Fields)
const schema = S.parseJson(S.Struct({ root: A }))
const decode = S.decodeUnknownEither(schema)import { Schema as S } from "@effect/schema";
const D = S.TaggedStruct("D", { content: S.String, })
const A = S.suspend(() => S.Struct({ component: S.Union(B, C, D) }),)
const Fields: S.Struct.Fields = { children: S.Array(A), };
const C = S.TaggedStruct("C", Fields)
const B = S.TaggedStruct("B", Fields)
const schema = S.parseJson(S.Struct({ root: A }))
const decode = S.decodeUnknownEither(schema)The error is the following over the "schema" token on the last line:
Argument of type 'SchemaClass<{ readonly root: { readonly component: { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly content: string; readonly _tag: "Text"; }; }; }, string, unknown>' is not assignable to parameter of type 'Schema<{ readonly root: { readonly component: { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly content: string; readonly _tag: "Text"; }; }; }, string, never>'.
The types of '[TypeId]._R' are incompatible between these types.
Type 'Covariant<unknown>' is not assignable to type 'Covariant<never>'.
Type 'unknown' is not assignable to type 'never'.ts(2345)Argument of type 'SchemaClass<{ readonly root: { readonly component: { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly content: string; readonly _tag: "Text"; }; }; }, string, unknown>' is not assignable to parameter of type 'Schema<{ readonly root: { readonly component: { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly [x: string]: any; readonly [x: number]: any; readonly [x: symbol]: any; } | { readonly content: string; readonly _tag: "Text"; }; }; }, string, never>'.
The types of '[TypeId]._R' are incompatible between these types.
Type 'Covariant<unknown>' is not assignable to type 'Covariant<never>'.
Type 'unknown' is not assignable to type 'never'.ts(2345)Note that
S.decodeUnknownS.decodeUnknown has no problem with it.