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:
Daishi Kato 2022-07-21 08:15:06 +09:00 committed by GitHub
parent f5490a1512
commit 0938b17a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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)
})
})