fix(types): properly infer return type from async setup (#2051)
fix #2049
This commit is contained in:
@@ -864,3 +864,39 @@ describe('extract instance type', () => {
|
||||
// @ts-expect-error
|
||||
expectError((compA.baseA = 1))
|
||||
})
|
||||
|
||||
describe('async setup', () => {
|
||||
type GT = string & { __brand: unknown }
|
||||
const Comp = defineComponent({
|
||||
async setup() {
|
||||
// setup context
|
||||
return {
|
||||
a: ref(1),
|
||||
b: {
|
||||
c: ref('hi')
|
||||
},
|
||||
d: reactive({
|
||||
e: ref('hello' as GT)
|
||||
})
|
||||
}
|
||||
},
|
||||
render() {
|
||||
// assert setup context unwrapping
|
||||
expectType<number>(this.a)
|
||||
expectType<string>(this.b.c.value)
|
||||
expectType<GT>(this.d.e)
|
||||
|
||||
// setup context properties should be mutable
|
||||
this.a = 2
|
||||
}
|
||||
})
|
||||
|
||||
const vm = {} as InstanceType<typeof Comp>
|
||||
// assert setup context unwrapping
|
||||
expectType<number>(vm.a)
|
||||
expectType<string>(vm.b.c.value)
|
||||
expectType<GT>(vm.d.e)
|
||||
|
||||
// setup context properties should be mutable
|
||||
vm.a = 2
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user