Skip to content

Type inference for advanced linkedSignal signature #60423

@JoostK

Description

@JoostK

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

The signature of linkedSignal that takes an object with source and computation properties does not allow for proper type inference, given the cyclic nature of the previous argument of the computation. Even though previous.value uses NoInfer to block TypeScript from picking up inferences from this position, TypeScript is still unable to infer type arguments if they are omitted:

const user = signal('Joost');
const linked = linkedSignal({
  source: user,
  computation: (user) => user.length,
});

Here, linked is inferred as WritableSignal<unknown> instead of WritableSignal<number>.

Please provide a link to a minimal reproduction of the bug

TypeScript playground

Metadata

Metadata

Assignees

Labels

area: coreIssues related to the framework runtimecore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: signals

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions