mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
fix(shallow): types with useStore again (#1117)
* add failing test * avoid function overload * simplify types * add unsupported test cases * Update src/shallow.ts * run prettier
This commit is contained in:
parent
f5490a1512
commit
0938b17a77
@ -1,11 +1,3 @@
|
||||
function shallow<T extends (...args: any[]) => any>(objA: T, objB: T): boolean
|
||||
|
||||
function shallow<T extends string | number | boolean>(objA: T, objB: T): boolean
|
||||
|
||||
function shallow<T extends any[]>(objA: T, objB: T): boolean
|
||||
|
||||
function shallow<T extends Record<string, any>>(objA: T, objB: T): boolean
|
||||
|
||||
function shallow<T>(objA: T, objB: T) {
|
||||
if (Object.is(objA, objB)) {
|
||||
return true
|
||||
|
||||
@ -67,4 +67,29 @@ describe('types', () => {
|
||||
}
|
||||
expect(Component).toBeDefined()
|
||||
})
|
||||
|
||||
it('works with useStore and string selector (#1107)', () => {
|
||||
const useStore = create(() => ({
|
||||
refetchTimestamp: '',
|
||||
}))
|
||||
const Component = () => {
|
||||
const refetchTimestamp = useStore(
|
||||
(state) => state.refetchTimestamp,
|
||||
shallow
|
||||
)
|
||||
return <>{refetchTimestamp.toUpperCase()}</>
|
||||
}
|
||||
expect(Component).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('unsupported cases', () => {
|
||||
it('date', () => {
|
||||
expect(
|
||||
shallow(
|
||||
new Date('2022-07-19T00:00:00.000Z'),
|
||||
new Date('2022-07-20T00:00:00.000Z')
|
||||
)
|
||||
).not.toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user