Effect CommunityEC
Effect Community2y ago
5 replies
joepjoosten

Issue with Generic Schema.Struct in TypeScript

Can't use generic Schema.Struct in function

import { Schema } from '@effect/schema';

const GenericStruct = <T extends Schema.Schema.All>(x: T) =>
  Schema.Struct({
    x: x,
  });

const obj = GenericStruct(Schema.Number);
// This is ok, obj is of type:
// Schema.Struct<{
//    x: Schema.$Number;
// }>

export type GenericStruct<T extends Schema.Schema.All> = Schema.Schema.Type<ReturnType<typeof GenericStruct<T>>>;

function doesNotCompile<T extends Schema.Schema.All>(obj: GenericStruct<T>) {
  obj.x; // <-- Property 'x' does not exist on type 'Simplify<Type<{ x: T; }>>'.ts(2339)
}


Why doesn't this simplify? Is this a limitation of typescript?
Was this page helpful?