Effect CommunityEC
Effect Community17mo ago
9 replies
ReallyWeird

Determining Schema Correspondence to Schema.Class in TypeScript

New question, I'm having some TS trouble in determining whether a Schema corresponds to a Schema.Class:
import { Schema as S } from '@effect/schema';

class Bar extends S.Class<Bar>('Bar')({
    bar: S.Number
}) {}

class Foo1 extends S.Class<Foo1>('Foo')({
    foo: S.String,
    ...Bar.fields
}) {}

class Foo2 extends S.Class<Foo2>('Foo2')({
    foo: S.String
}) {}

class Foo3 extends S.Class<Foo3>('Foo3')({
}) {}

class Foo4 extends Bar.extend<Foo4>('Foo4') ({
    foo: S.String
}) {}

type isClass<S> = S extends S.Class<any, any, any, any, any, any, any> ? true : false;

type A = isClass<Foo1>;
//   ^? type A = false
type B = isClass<typeof Foo1>;
//   ^? type B = false
type C = isClass<Foo2>;
//   ^? type C = false
type D = isClass<typeof Foo2>;
//   ^? type D = false
type E = isClass<Foo3>;
//   ^? type E = false
type F = isClass<typeof Foo3>;
//   ^? type F = true
type G = isClass<Foo4>;
//   ^? type G = false
type H = isClass<typeof Foo4>;
//   ^? type H = false

How come only without fields does the type guard work?
Was this page helpful?