Skip to content

coalesce() returns BasicExpression<any>, losing type inference #1341

@rohanajayjain

Description

@rohanajayjain

From discord: https://discord.com/channels/719702312431386674/1369767025723052134/1474732210967019644

Coalesce returns BasicExpression which means if you use it in .select(), all your fields end up typed as any. in my case I'm doing a full join + coalesce to merge two tables and the whole result loses its types.

Looking at the source it's just (...args: Array): BasicExpression so the generic is never inferred from the args.

For now I'm just casting the result but would be nice to get proper inference out of the box.

minimal example:

import { coalesce } from "@tanstack/db";

// coalesce always returns BasicExpression<any>, losing type info
const a = coalesce("hello", "world"); // BasicExpression<any>
const b = coalesce(1, 2);            // BasicExpression<any>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions