type Part = S.Schema<any, string>;
const PK = (...parts: readonly Part[]) => {
return S.asSchema(S.compose(S.asSchema(S.split('#')), S.Tuple(...parts)));
};
export const Item = S.Struct({
PK: PK(
S.String, // OK
S.NumberFromString, // OK
S.Date, // OK
S.String.pipe(S.brand('EntityAId')), // OK
S.String.pipe(S.brand('EntityBId')), // OK
S.String.pipe(S.pattern(/^(?:TextA|TextB)$/)), // OK
// @ts-expect-error
S.Literal('LiteralA', 'LiteralB'), // ERROR
// Argument of type 'Literal<["LiteralA", "LiteralB"]>' is not assignable to parameter of type 'Part'.
// The types of '[TypeId]._I' are incompatible between these types.
// Type 'Invariant<"LiteralA" | "LiteralB">' is not assignable to type 'Invariant<string>'.
// Types of parameters '_' and '_' are incompatible.
// Type 'string' is not assignable to type '"LiteralA" | "LiteralB"'.ts(2345)
),
});
type Part = S.Schema<any, string>;
const PK = (...parts: readonly Part[]) => {
return S.asSchema(S.compose(S.asSchema(S.split('#')), S.Tuple(...parts)));
};
export const Item = S.Struct({
PK: PK(
S.String, // OK
S.NumberFromString, // OK
S.Date, // OK
S.String.pipe(S.brand('EntityAId')), // OK
S.String.pipe(S.brand('EntityBId')), // OK
S.String.pipe(S.pattern(/^(?:TextA|TextB)$/)), // OK
// @ts-expect-error
S.Literal('LiteralA', 'LiteralB'), // ERROR
// Argument of type 'Literal<["LiteralA", "LiteralB"]>' is not assignable to parameter of type 'Part'.
// The types of '[TypeId]._I' are incompatible between these types.
// Type 'Invariant<"LiteralA" | "LiteralB">' is not assignable to type 'Invariant<string>'.
// Types of parameters '_' and '_' are incompatible.
// Type 'string' is not assignable to type '"LiteralA" | "LiteralB"'.ts(2345)
),
});