Effect CommunityEC
Effect Community17mo ago
5 replies
kondaurovdev

TypeScript Compilation Error with Custom Getter in MySchema

Hi all,
I'm getting error in this snippet when I use custom getter prop2 in MySchema

import { Schema as S } from "@effect/schema"

class MySchema 
  extends S.Class<MySchema>("MySchema")({
    prop1: S.NonEmptyString
  }) {

    get prop2() { return "prop2" } 

  }

const check = <I>(
  customSchema: S.Schema<I>,
  input: unknown
) =>
  S.decodeUnknown(customSchema)(input)


const res1 = check(MySchema, {})


I get compilation error:

type 'Schema<MySchema, readonly []>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
          The types returned by 'arbitrary(...)' are incompatible between these types.
            Type 'LazyArbitrary<{ readonly prop1: string; }>' is not assignable to type 'LazyArbitrary<MySchema>'.
              Type '{ readonly prop1: string; }' is not assignable to type 'MySchema'.ts(2345)


But it works when prop2 is commented out

I don't understand that error and how to fix it
Was this page helpful?