-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Open
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecore: reactivityWork related to fine-grained reactivity in the core frameworkWork related to fine-grained reactivity in the core frameworkcross-cutting: signalscross-cutting: types
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core, Don't known / other
Is this a regression?
No
Description
The current implementation of signals uses a function to access the value, and TypeScript has issues with type guards in that case:
const count = signal(null as null | number);
const total: number = count() !== null ? count() : 0;
// Error: Type `number | null` is not assignable to type `number`
This can be workaround by storing the value in a temporary variable or with an explicit cast, but this could be a bit cumbersome, as I imagine the same would happen with ngIf
in templates:
const count = signal(null as null | number);
const value = count();
const total: number = value !== null ? value : 0;
// Works
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
No response
Anything else?
No response
vneogi199, eneajaho, tonivj5, Harpush, HyperLife1119 and 137 more
Metadata
Metadata
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecore: reactivityWork related to fine-grained reactivity in the core frameworkWork related to fine-grained reactivity in the core frameworkcross-cutting: signalscross-cutting: types
Type
Projects
Status
In Progress