When using selectors with parameters in NGXS, you return a create selector function, but this way I need to set the return type of the single selector to any and it actually is AccountDetails.
@Selector([AccountsDbState])
public static single(id: string): any {
return createSelector([AccountsDbState], (state: RootStateModel) => {
return state.database.accounts.items.find(x => x.id === id);
});
}
If try to type it as AccountDetails I get the following error from intellisense:
Type '(state: RootStateModel) => AccountDetails' is missing the following properties from type 'AccountDetails': id, code, openingBalance, openingDate, and 3 more.ts(2740)
Is there any way to correctly type this kind of selectors?
--- UPDATE ---
Full selector file contents:
import { createSelector, Selector } from '@ngxs/store';
import { AccountDetails } from '@models/accounts';
import { RootStateModel } from '@state/root-state';
import { AccountsDbState } from './accounts.state';
import { DatabaseStoreStateModel } from 'ngx-rbk-utils';
export class AccountsDbSelectors {
@Selector([AccountsDbState])
public static all(state: DatabaseStoreStateModel<AccountDetails>): AccountDetails[] {
return state.items;
}
@Selector([AccountsDbState])
public static single(id: string): any {
return createSelector([AccountsDbState], (state: RootStateModel) => {
return state.database.accounts.items.find(x => x.id === id);
});
}
}
The examples in the NGXS Selector documentation don't set return types in any function :(