Skip to content

toSignal() can not be called inside computed() #50106

@e-oz

Description

@e-oz

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

core

Is this a regression?

No

Description

toSignal() can not set internal state (state.set() when called from computed(), because of NG0600 ("Writing to signals is not allowed in a computed or an effect by default").

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-hjphb7?devToolsHeight=33&file=src/main.ts

Please provide the exception or error you saw

ERROR
Error: NG0601: `toSignal()` called with `requireSync` but `Observable` did not emit synchronously.

ERROR
Error: NG0600: Writing to signals is not allowed in a `computed` or an `effect` by default. Use `allowSignalWrites` in the `CreateEffectOptions` to enable this inside effects.

Please provide the environment you discovered this bug in (run ng version)

@angular/core 16.0.0-rc.4

Anything else?

It is reproducible without Component's template, so the issue is not caused by the template: https://stackblitz.com/edit/angular-rbp4uq?devToolsHeight=33&file=src/main.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: clarificationThis issue needs additional clarification from the reporter before the team can investigate.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions