Title: TypeScript Inference Issue with Optional Schema in Function

am i doing something wrong here or expecting a little too much from typescript inference? at the Schema.decodeUnknown(opts.schema) line im still getting a Type 'undefined' is not assignable to type 'Schema<A, I, never>' ts error...

  function get<A, I>(url: string, opts?: ApiClientOptions<A, I>) {
    return pipe(
      Effect.tryPromise({
        try: (signal) => $fetch<A>(url, { ...options, baseURL, ...opts, method: "GET", signal }),
        catch: _handleError,
      }),
      Effect.flatMap((result) =>
        Effect.if(Predicate.isNotUndefined(opts?.schema), {
          onTrue: () => Schema.decodeUnknown(opts.schema)(result),
          onFalse: () => Effect.succeed(result),
        }),
      ),
    );
  }
Was this page helpful?