Skip to content

Commit

Permalink
types(internal): provide internal options for using $el type in lan…
Browse files Browse the repository at this point in the history
…guage tools (#11814)
  • Loading branch information
KazariEX authored Sep 5, 2024
1 parent 3c0d531 commit 7a64b67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages-private/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,15 @@ describe('__typeRefs backdoor, object syntax', () => {
expectType<number>(refs.child.$refs.foo)
})

describe('__typeEl backdoor', () => {
const Comp = defineComponent({
__typeEl: {} as HTMLAnchorElement,
})
const c = new Comp()

expectType<HTMLAnchorElement>(c.$el)
})

defineComponent({
props: {
foo: [String, null],
Expand Down
12 changes: 10 additions & 2 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type DefineComponent<
Provide extends ComponentProvideOptions = ComponentProvideOptions,
MakeDefaultsOptional extends boolean = true,
TypeRefs extends Record<string, unknown> = {},
TypeEl extends Element = any,
> = ComponentPublicInstanceConstructor<
CreateComponentPublicInstanceWithMixins<
Props,
Expand All @@ -86,7 +87,8 @@ export type DefineComponent<
LC & GlobalComponents,
Directives & GlobalDirectives,
Exposed,
TypeRefs
TypeRefs,
TypeEl
>
> &
ComponentOptionsBase<
Expand Down Expand Up @@ -214,6 +216,7 @@ export function defineComponent<
: { [key in RuntimePropsKeys]?: any }
: TypeProps,
TypeRefs extends Record<string, unknown> = {},
TypeEl extends Element = any,
>(
options: {
props?: (RuntimePropsOptions & ThisType<void>) | RuntimePropsKeys[]
Expand All @@ -229,6 +232,10 @@ export function defineComponent<
* @private for language-tools use only
*/
__typeRefs?: TypeRefs
/**
* @private for language-tools use only
*/
__typeEl?: TypeEl
} & ComponentOptionsBase<
ToResolvedProps<InferredProps, ResolvedEmits>,
SetupBindings,
Expand Down Expand Up @@ -289,7 +296,8 @@ export function defineComponent<
// MakeDefaultsOptional - if TypeProps is provided, set to false to use
// user props types verbatim
unknown extends TypeProps ? true : false,
TypeRefs
TypeRefs,
TypeEl
>

// implementation, close to no-op
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export type CreateComponentPublicInstanceWithMixins<
Directives extends Record<string, Directive> = {},
Exposed extends string = string,
TypeRefs extends Data = {},
TypeEl extends Element = any,
Provide extends ComponentProvideOptions = ComponentProvideOptions,
// mixin inference
PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
Expand Down Expand Up @@ -277,7 +278,8 @@ export type CreateComponentPublicInstanceWithMixins<
I,
S,
Exposed,
TypeRefs
TypeRefs,
TypeEl
>

export type ExposedKeys<
Expand All @@ -302,6 +304,7 @@ export type ComponentPublicInstance<
S extends SlotsType = {},
Exposed extends string = '',
TypeRefs extends Data = {},
TypeEl extends Element = any,
> = {
$: ComponentInternalInstance
$data: D
Expand All @@ -315,7 +318,7 @@ export type ComponentPublicInstance<
$parent: ComponentPublicInstance | null
$host: Element | null
$emit: EmitFn<E>
$el: any
$el: TypeEl
$options: Options & MergedComponentOptionsOverride
$forceUpdate: () => void
$nextTick: typeof nextTick
Expand Down

0 comments on commit 7a64b67

Please sign in to comment.