Skip to content

Swap computedFrom<Input, Output> to computedFrom<Output, Input>? #73

@renatoaraujoc

Description

@renatoaraujoc

Hello @nartc and @eneajaho,

After a talk with Enea on Twitter, I've shown that maybe we could improve computedFrom type inference.

Right now, we can't easily tell computedFrom what kind of Output type we want it to be unless we specify the Input params first.

Right now we need to do this:

someNumber = signal<number | null>(null);

computedNumberToSomething = computedFrom<[number | null], number>(
    [this.someNumber],
    pipe(map(([someNumber]) => someNumber ?? 0))
);

Could we have something like:

someNumber = signal<number | null>(null);

computedNumberToSomething = computedFrom<number>(
    [this.someNumber],
    pipe(map(([someNumber]) => someNumber ?? 0))
);

It would be needed to swap <Input, Output> to <Output, Input> in computedFrom.

Second feedback:

Create an overloaded function that also accepts a non readonly array, so we can:

someNumber = signal<number | null>(null);

computedNumberToSomething = computedFrom<number>(
    this.someNumber,
    pipe(map(([someNumber]) => someNumber ?? 0))
);

What yall think?

Renato

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