ComponentOptionsWithArrayProps,
ComponentOptionsWithObjectProps,
ComponentOptionsMixin,
- RenderFunction
+ RenderFunction,
+ UnwrapAsyncBindings
} from './componentOptions'
import {
SetupContext,
): ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
Props,
- RawBindings,
+ UnwrapAsyncBindings<RawBindings>,
{},
{},
{},
): ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
Props,
- RawBindings,
+ UnwrapAsyncBindings<RawBindings>,
D,
C,
M,
// but now we can export array props in TSX
CreateComponentPublicInstance<
Readonly<{ [key in PropNames]?: any }>,
- RawBindings,
+ UnwrapAsyncBindings<RawBindings>,
D,
C,
M,
): ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
ExtractPropTypes<PropsOptions, false>,
- RawBindings,
+ UnwrapAsyncBindings<RawBindings>,
D,
C,
M,
export type RenderFunction = () => VNodeChild
+export type UnwrapAsyncBindings<T> = T extends Promise<infer S> ? S : T
+
export interface ComponentOptionsBase<
Props,
RawBindings,
OptionTypesType,
OptionTypesKeys,
resolveMergedOptions,
- isInBeforeCreate
+ isInBeforeCreate,
+ UnwrapAsyncBindings
} from './componentOptions'
import { EmitsOptions, EmitFn } from './componentEmits'
import { Slots } from './componentSlots'
options?: WatchOptions
): WatchStopHandle
} & P &
- ShallowUnwrapRef<B> &
+ ShallowUnwrapRef<UnwrapAsyncBindings<B>> &
D &
ExtractComputedReturns<C> &
M &
// @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
+})