From 6fc8d5d0ba79691b7814ecb472bd89c8a15a3d10 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Nov 2020 00:01:44 -0500 Subject: [PATCH] wip: type inference for useOptions --- .../runtime-core/src/helpers/useOptions.ts | 78 +++++++++++++-- test-dts/useOptions.test-d.ts | 96 +++++++++++++++++++ 2 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 test-dts/useOptions.test-d.ts diff --git a/packages/runtime-core/src/helpers/useOptions.ts b/packages/runtime-core/src/helpers/useOptions.ts index 172b2aaa..055f2807 100644 --- a/packages/runtime-core/src/helpers/useOptions.ts +++ b/packages/runtime-core/src/helpers/useOptions.ts @@ -1,22 +1,88 @@ +import { EmitFn, EmitsOptions } from '../componentEmits' +import { + ComponentObjectPropsOptions, + ExtractPropTypes +} from '../componentProps' import { Slots } from '../componentSlots' +import { Directive } from '../directives' import { warn } from '../warning' interface DefaultContext { - props: Record + props: {} attrs: Record emit: (...args: any[]) => void slots: Slots } +interface InferredContext { + props: Readonly

+ attrs: Record + emit: EmitFn + slots: Slots +} + +type InferContext, P, E> = { + [K in keyof DefaultContext]: T[K] extends {} ? T[K] : InferredContext[K] +} + +/** + * This is a subset of full options that are still useful in the context of + *