Skip to content

Commit

Permalink
feat(syncRef): enhance type (#3678)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed Dec 27, 2023
1 parent 0c246cc commit dad663e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/shared/syncRef/index.test.ts
Expand Up @@ -102,6 +102,7 @@ describe('syncRef', () => {
const ref0 = ref(0)
const ref1 = ref(1)
const refString = ref('1')
const refNumber = ref(1)
const refNumString = ref<number | string>(1)
const refNumBoolean = ref<number | boolean>(1)
// L = A && direction === 'both'
Expand Down Expand Up @@ -253,5 +254,12 @@ describe('syncRef', () => {
const bool0 = ref(false)
const bool1 = ref(false)
syncRef(bool0, bool1)

syncRef(refNumber, refString, {
// @ts-expect-error lack rtl func
transform: {
ltr: v => String(v),
},
})
})
})
2 changes: 1 addition & 1 deletion packages/shared/syncRef/index.ts
Expand Up @@ -130,7 +130,7 @@ export type SyncRefOptions<L, R, D extends Direction> = ConfigurableFlushSync &
* 3. L ⊆ R
* 4. L ∩ R = ∅
*/
export function syncRef<L, R, D extends Direction>(
export function syncRef<L, R, D extends Direction = 'both'>(
left: Ref<L>,
right: Ref<R>,
...[options]: Equal<L, R> extends true
Expand Down

0 comments on commit dad663e

Please sign in to comment.