Skip to content

Commit

Permalink
fix(types): should unwrap tuple correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed May 26, 2021
1 parent 30e3ddf commit ffabf44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reactivity/ref.ts
Expand Up @@ -31,7 +31,7 @@ export type UnwrapRef<T> = T extends Ref<infer V>

type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
? T
: T extends Array<any>
: T extends any[] | readonly any[]
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
: T extends object
? UnwrappedObject<T>
Expand Down
11 changes: 11 additions & 0 deletions test-dts/reactivity.test-d.ts
@@ -0,0 +1,11 @@
import { ref, Ref, reactive, expectType } from './index'

describe('should unwrap tuple correctly', () => {
const readonlyTuple = [ref(0)] as const
const reactiveReadonlyTuple = reactive(readonlyTuple)
expectType<Ref<number>>(reactiveReadonlyTuple[0])

const tuple: [Ref<number>] = [ref(0)]
const reactiveTuple = reactive(tuple)
expectType<Ref<number>>(reactiveTuple[0])
})

0 comments on commit ffabf44

Please sign in to comment.