fix(types): properly infer return type from async setup (#2051)

fix #2049
This commit is contained in:
HcySunYang
2020-09-14 23:28:56 +08:00
committed by GitHub
parent 0124eacc91
commit 24fcf6ae7c
4 changed files with 47 additions and 7 deletions

View File

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