Skip to content

Generic Functions Type Error #25

Description

@jkonowitch

Example 1

  const minimalRepro = <A, E>(
    fn: () => AsyncResult<A, E>
  ): AsyncResult<A, E> => {
    return Result.gen(function* () {
      const r = yield* fn();
      return Result.ok(r);
    })
  }

Expected behavior

This should compile

Actual Behavior

Type 'AsyncResult<ExtractValue<Ok<A>>, E | InferError<Ok<A>>>' is not assignable to type 'AsyncResult<A, E>'.
Type 'ExtractValue<Ok<A>>' is not assignable to type 'A'.
'A' could be instantiated with an arbitrary type which could be unrelated to 'ExtractValue<Ok<A>>'. (ts 2322)

Example 2

  const minimalRepro2 = <A, E>(
    fn: () => AsyncResult<A, E>
  ): AsyncResult<A, E> => {
    return fn().map(a => a);
  }

Expected Behavior

This should compile

Actual Behavior

Type '[A] extends [never] ? AsyncResult<A, E> : [A] extends [Generator<unknown, any, any> | AsyncGenerator<unknown, any, any>] ? AsyncResult<...> : [...] extends [...] ? PValue extends A ? AsyncResult<...> : never : A extends A ? AsyncResult<...> : never' is not assignable to type 'AsyncResult<A, E>'.
Type 'AsyncResult<A, E> | ([A] extends [Generator<unknown, any, any> | AsyncGenerator<unknown, any, any>] ? AsyncResult<InferGeneratorReturn<A>, E | InferGeneratorError<...>> : [...] extends [...] ? PValue extends A ? AsyncResult<...> : never : A extends A ? AsyncResult<...> : never)' is not assignable to type 'AsyncResult<A, E>'.
Type '[A] extends [Generator<unknown, any, any> | AsyncGenerator<unknown, any, any>] ? AsyncResult<InferGeneratorReturn<A>, E | InferGeneratorError<...>> : [...] extends [...] ? PValue extends A ? AsyncResult<...> : never : A extends A ? AsyncResult<...> : never' is not assignable to type 'AsyncResult<A, E>'.
Type 'AsyncResult<InferGeneratorReturn<A>, E | InferGeneratorError<A>> | ([A] extends [Promise<infer PValue>] ? PValue extends A ? AsyncResult<...> : never : A extends A ? AsyncResult<...> : never)' is not assignable to type 'AsyncResult<A, E>'.
Type 'AsyncResult<InferGeneratorReturn<A>, E | InferGeneratorError<A>>' is not assignable to type 'AsyncResult<A, E>'.
Type 'E | InferGeneratorError<A>' is not assignable to type 'E'.
'E' could be instantiated with an arbitrary type which could be unrelated to 'E | InferGeneratorError<A>'. (ts 2322)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions