-
I'm working on an angular app which uses a service with generics. In most cases I have been putting the creation of the store, and plugins outside the angular service and simply calling them, but in this case I need to create the store in the constructor. But I'm struggling with all the type parameters to the store and plugins. what is the correct way to get the type of a store? export class MyService<T extends MyThing> {
store: ??? // how can I get the type of this.store?
constructor() {
this.store = createStore(
{ name: 'mystore' },
withEntities<T>(),
withActiveId()
)
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
leon
Aug 19, 2022
Replies: 2 comments
-
export class MyService<T extends MyThing> {
store = createStore(
{ name: 'mystore' },
withEntities<T>(),
withActiveId()
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
The answer I was looking for is: import { createStore, StoreDef, StoreValue } from '@ngneat/elf'
import { withEntities, withActiveId } from '@ngneat/elf-entities'
const myStore = createStore(
{ name: 'mystore' },
withEntities<T>(),
withActiveId()
)
type MyStore = StoreDef<StoreValue<typeof myStore>> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
leon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The answer I was looking for is: