Skip to content

Type inference error when using .andThrough() #663

@msickpaler

Description

@msickpaler

When using .andThrough() with a function that returns a Result, TypeScript reports a type mismatch, even though the function signature should be compatible.

part of code

ok({
  title: "title",
  description: "description",
})
  .andThen((s) => ok(s))
  .andThrough(assertPublishable) // <= error happen

current return type

Result<{
    title: string;
    description: string;
}, Error_A>

expected return type

Result<{
    title: string;
    description: string;
}, Error_A | Error_B>

Curiously, if I comment out .andThen((s) => ok(s)), the error disappears and the return type becomes exactly as expected.

typescript playground is here

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgUylANHCBrOBfOAMyghDgCIA7ZAN1RgAsSB3cgbgCgOBjAGwEMAzoLgBRNNAD6AQRQAPGMkoATEeJJREHOHDBRgNforhRk-ZREq8AnnEkxrYZAC4K6qdPZcd3S4JhQAK7cMNAAFCDIwvwA5i5w-vqUMQCUWjo6goFOUBFRgrHIKZwZcIzAggB09o7IcAC8bhJQMl46eBwdfEJqzZIAQvKKKr0a6br6hsam5pY2dg5OruTuLf1e2nC+lInBobmR0XGuicDJaQibmdmoeUdFJRnlVTVODU0aA234nVzb-nAevQAAqBABGvAqDH4ELqjTCgko-DAggYEBgrkuOhgwBgvHip2Sj2UUW4+jAOMsJwCZxinDwaXqAD5xsBCHAwgBCRHI1Hoyo4vFFcY6UwwQJQSgoNBhajMMR9aRhcioDSeFLFTYdHRsjncpEotEwSokwRk4AU4CWC5XEzIcWS6W5OUKz79ZWq6DrDWPbV2h1SnBhTV4TgcINYsq4-HLQX48joTam82WqkUZPkymUBOdFKbSr8FQAFQYSjCCMZLKDgg1+cLyhLJECMQYYSBsFBEKhMPxmqAA

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