Effect CommunityEC
Effect Community16mo ago
9 replies
kondaurovdev

TypeScript Compilation Error: Missing Properties in Schema

Hi, why this code doesn't compile?

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

const MyConfig =
  S.Struct({
    num: S.suspend(() => NumberWithDefault)
  })

const NumberWithDefault = 
  pipe(
    S.Number,
    S.lessThan(10),
    S.optionalWith({ default: () => 1})
  )


error:
Type 'optionalWith<filter<Schema<number, number, never>>, { default: () => number; }>' is missing the following properties from type 'Schema<any, any, unknown>': Type, Encoded, Contextts(2739)
Schema.d.ts(1504, 44): The expected type comes from the return type of this signature.
const NumberWithDefault: S.optionalWith<S.filter<S.Schema<number, number, never>>, {
    default: () => number;
}>
Was this page helpful?