forked from ngrx/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(signals): patch state methods do not correctly resolve generic co…
…llection names withEntities Ensures type-safety of named entity collections with patchState helpers fixes ngrx#4638
- Loading branch information
1 parent
34d18af
commit 4f7181f
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expecter } from 'ts-snippet'; | ||
import { compilerOptions } from './helpers'; | ||
|
||
describe('models', () => { | ||
const expectSnippet = expecter( | ||
(code) => ` | ||
import { patchState, signalStore, type, withMethods } from '@ngrx/signals'; | ||
import { addEntity, entityConfig, withEntities } from '@ngrx/signals/entities'; | ||
type User = { id: number; name: string }; | ||
${code} | ||
`, | ||
compilerOptions() | ||
); | ||
|
||
it('succeeds when entity collection name is passed as the type parameter', () => { | ||
const snippet = ` | ||
const storeFactory = <Collection extends string>( | ||
collection: Collection | ||
) => { | ||
const Store = signalStore( | ||
withEntities({ entity: type<User>(), collection: collection }), | ||
withMethods((store) => ({ | ||
addUsers(user: User): void { | ||
patchState(store, addEntity(user, { collection: collection })); | ||
}, | ||
})) | ||
); | ||
return new Store(); | ||
}; | ||
`; | ||
|
||
expectSnippet(snippet).toSucceed(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters