Experiencing frustration with setting initialValue to true for a signal, encountering the error message (TS2769: No overload matches this call).
The Observable does return an Observable.
A workaround was found by omitting the "initialValue" option and adding "as Signal," although not entirely satisfying as the root cause remains unclear.
If there are any insights or feedback on signal usage and the provided code, it would be greatly appreciated:
export class HeaderComponent implements OnInit {
private readonly injector = inject(Injector);
constructor(private scrollDispatcher: ScrollDispatcher,private viewportRuler:ViewportRuler) {}
ngOnInit(): void {
this.scrollLimit = toSignal<boolean>(this.scrollDispatcher.scrolled()
.pipe(
map(()=> this.viewportRuler.getViewportScrollPosition().top),
map((top) => top < 349)
), {injector: this.injector, intialValue: true}) ;
}
}
Provided below is the current workaround that functions:
this.scrollLimit = toSignal<boolean>(this.scrollDispatcher.scrolled()
.pipe(
startWith(void 0),
map(()=> this.viewportRuler.getViewportScrollPosition().top),
map((top) => top < 349)
), {injector: this.injector}) as Signal<boolean>;