Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(syncRef): enhance type #3678

Merged
merged 1 commit into from Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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