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

From Where I need to import the ZustandBaseService #11

Open
Syammed2429 opened this issue May 20, 2024 · 6 comments
Open

From Where I need to import the ZustandBaseService #11

Syammed2429 opened this issue May 20, 2024 · 6 comments

Comments

@Syammed2429
Copy link

Syammed2429 commented May 20, 2024

import { Injectable } from '@angular/core';


interface CounterState {
  counter: number;
  increment: () => void;
  // decrement: () => void;
}

@Injectable({
  providedIn: 'root',
})
export class CounterService extends ZustandBaseService<CounterState> {
  initStore() {
    return set => ({
      counter: 0,
      increment: counter => set({ counter }),
      // decrement: () => set(state => ({ counter: state.counter - 1 })),
    });
  }
}

I did something like that , but it's throwing an error like Cannot find name 'ZustandBaseService'.ts(2304) so from where I can import it??

@Syammed2429
Copy link
Author

@JoaoPauloLousada

@JoaoPauloLousada
Copy link
Owner

you should be able to import it from the lib.|
import { ZustandBaseService } from 'ngx-zustand';

@Syammed2429
Copy link
Author

How can I use the persist store for this I tried but I end up with lots of an errors, could you please help me @JoaoPauloLousada

@Syammed2429
Copy link
Author

import { Injectable } from '@angular/core';

import { ZustandBaseService } from 'ngx-zustand';

interface CounterState {
  counter: number;
  increment: () => void;
  decrement: () => void;
}

@Injectable({
  providedIn: 'root',
})
export class CounterService extends ZustandBaseService<CounterState> {
  initStore() {
    return set => ({
      counter: 0,
      increment: () => set(state => ({ counter: state.counter + 1 })),
      decrement: () => set(state => ({ counter: state.counter - 1 })),
    });
  }
}

some errors

Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:53 - error TS1005: '>' expected.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                       ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:58 - error TS1005: ',' expected.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                            ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:60 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                              ~~~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:63 - error TS1005: ';' expected.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                                 ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:64 - error TS1128: Declaration or statement expected.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                                  ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:66 - error TS2348: Value of type 'typeof Observable' is not callable. Did you mean to include 'new'?

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                                    ~~~~~~~~~~~~~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:77 - error TS2304: Cannot find name 'S'.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                                               ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:13:79 - error TS1005: '(' expected.

13     useStore<S>(selector: Parameters<typeof useStore<T, S>>[1]): Observable<S>;
                                                                                 ~


Error: node_modules/ngx-zustand/lib/zustand-base.service.d.ts:14:1 - error TS1128: Declaration or statement expected.

14 }
    

@JoaoPauloLousada

@Marcial1234
Copy link

Marcial1234 commented Jun 3, 2024

This seems to be a TypeScript issue @Syammed2429 - check your compiler version and check if it's up to date.
If it is, it's likely the lib's TS version is not compatible with yours (libraries last update was ~18 months ago?), in that case you'd need to modify your tsconfig.json to be less strict

Seems duplicate of #10

@JoaoPauloLousada
Copy link
Owner

@Marcial1234 please feel free to contribute to the project :)
Adding backwards compatibility with old typescript and angular versions would be awesome.

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

3 participants