Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toLazySignal broken with Angular 18.1.x #474

Open
SpeedoPasanen opened this issue Jul 30, 2024 · 5 comments
Open

toLazySignal broken with Angular 18.1.x #474

SpeedoPasanen opened this issue Jul 30, 2024 · 5 comments

Comments

@SpeedoPasanen
Copy link

ToSignalOptions in @angular/core/rxjs-interop now requires a generic type, which breaks toLazySignal because it's options doesn't have a type.

Only workaround I can think of is to roll back to Angular 18.0.x

@SpeedoPasanen SpeedoPasanen changed the title toLazySignal broken with Angular 18.1.2 toLazySignal broken with Angular 18.1.x Jul 30, 2024
@eneajaho
Copy link
Collaborator

or we just add a generic type too

@ShacharHarshuv
Copy link
Contributor

ShacharHarshuv commented Aug 14, 2024

Typing a generic type doesn't always work.

for example:

toLazySignal<string>(..., {
  requireSync: true
});

Infers as Signal<string | undefined> incorrectly. (Should be Signal<string>). Extracting the options to a separate variable with an explicit generic also doesn't work here.

I believe this update was caused by a typescript update. Looking at Angular's code, they changed the type definitions of toSignal to use NoInfer and pass a generic to options. If you do the same changes for toLazySignal it works:

export declare function toLazySignal<T>(source: Observable<T> | Subscribable<T>): Signal<T | undefined>;
export declare function toLazySignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | undefined> & {
    initialValue?: undefined;
    requireSync?: false;
}>): Signal<T | undefined>;
export declare function toLazySignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | null> & {
    initialValue?: null;
    requireSync?: false;
}>): Signal<T | null>;
export declare function toLazySignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T> & {
    initialValue?: undefined;
    requireSync: true;
}>): Signal<T>;
export declare function toLazySignal<T, const U extends T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | U> & {
    initialValue: U;
    requireSync?: false;
}>): Signal<T | U>;

So a better workaround than rolling back would be using patch-package with these changes, or creating your local copy of toLazySignal. Hopefully you can revert that once it gets fixed in ngxensions.

FYI, NoInfer was introduced in typescript 5.4, so that would mean ngxtension would have to add that as a minimum verison.

@eneajaho
Copy link
Collaborator

cc @e-oz

@e-oz
Copy link
Contributor

e-oz commented Aug 14, 2024

I'm on it

@e-oz
Copy link
Contributor

e-oz commented Aug 14, 2024

as soon as ngx-tension update its deps to 18.1+, tests in this PR will stop failing: #484 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants