in compilation modules are not correctly resolved
Closed this issue · 3 comments
Which @ngrx/* package(s) are the source of the bug?
signals
Minimal reproduction of the bug/regression with instructions
as you can see here i've defined a minimal store following the docs example; assigning a type to the store object defined in another library and then compiling i obtain that modules are not correctly resolved and the import points to the dist folder as you can see:
export declare const BooksStore: import("@angular/core").Type<{
books: import("@angular/core").Signal<import("dist/demo/test/lib/model").Book[]>;
isLoading: import("@angular/core").Signal<boolean>;
filter: import("@ngrx/signals").DeepSignal<{
query: string;
order: "asc" | "desc";
}>;
} & import("@ngrx/signals").StateSource<{
books: import("dist/demo/test/lib/model").Book[];
isLoading: boolean;
filter: {
query: string;
order: "asc" | "desc";
};
}>>;
Expected behavior
external types should be correctly imported
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
Ngrx: 18.0.2;
Angular: 18.2.0
Node: 20.11.0
operating system: MacOs
Other information
No response
I would be willing to submit a PR to fix this issue
- Yes
- No
Maybe that someone with more experience has an explanation for this, but I don't think this is something we can change and that this is just how the compilation works.
For some reason, adding the token within the same file as the store results in the desired output:
import { signalStore, withState } from '@ngrx/signals';
import { inject } from '@angular/core';
import { InjectionToken } from '@angular/core';
import { Model } from '@test/demo/test';
export const BOOKS_STATE = new InjectionToken<Model.BooksState>('BooksState', {
factory: () => Model.initialState,
});
export const BooksStore = signalStore(withState(() => inject(BOOKS_STATE)));
Results into:
import { InjectionToken } from '@angular/core';
import { Model } from '@test/demo/test';
export declare const BOOKS_STATE: InjectionToken<Model.BooksState>;
export declare const BooksStore: import("@angular/core").Type<{
books: import("@angular/core").Signal<Model.Book[]>;
isLoading: import("@angular/core").Signal<boolean>;
filter: import("@ngrx/signals").DeepSignal<{
query: string;
order: "asc" | "desc";
}>;
} & import("@ngrx/signals").StateSource<{
books: Model.Book[];
isLoading: boolean;
filter: {
query: string;
order: "asc" | "desc";
};
}>>;
Hello, I've tried in my real project and your solution works only if the state type does not contain external type references, otherwise types are not correctly inferred.
Moreover, i cannot understand why injecting the same state on two different components results in that:
Basically in one component the state correctly infers type and in the other no..
EDIT: maybe something related with typescript.. if i do not use namespaces for types export it seems to work as expected.. any idea or workaround?
@forgantini sorry, I do not have a solution for this.
I'm closing this issue because it isn't related to the NgRx repo.