Skip to content

Commit 5d932a8

Browse files
authored
fix(types): defineCustomElement using defineComponent return type with emits (#7937)
close #7782
1 parent 341b541 commit 5d932a8

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/dts-test/defineCustomElement.test-d.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { defineCustomElement } from 'vue'
2-
import { expectType, describe } from './utils'
1+
import {
2+
defineCustomElement,
3+
defineComponent,
4+
type VueElementConstructor
5+
} from 'vue'
6+
import { expectType, describe, test } from './utils'
37

48
describe('inject', () => {
59
// with object inject
@@ -62,3 +66,20 @@ describe('inject', () => {
6266
}
6367
})
6468
})
69+
70+
describe('defineCustomElement using defineComponent return type', () => {
71+
test('with emits', () => {
72+
const Comp1Vue = defineComponent({
73+
props: {
74+
a: String
75+
},
76+
emits: {
77+
click: () => true
78+
}
79+
})
80+
const Comp = defineCustomElement(Comp1Vue)
81+
expectType<VueElementConstructor>(Comp)
82+
83+
expectType<string | undefined>(new Comp().a)
84+
})
85+
})

packages/runtime-dom/src/apiCustomElement.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ComponentOptionsWithObjectProps,
55
ComponentOptionsWithoutProps,
66
ComponentPropsOptions,
7-
ComponentPublicInstance,
87
ComputedOptions,
98
EmitsOptions,
109
MethodOptions,
@@ -21,7 +20,8 @@ import {
2120
ConcreteComponent,
2221
ComponentOptions,
2322
ComponentInjectOptions,
24-
SlotsType
23+
SlotsType,
24+
DefineComponent
2525
} from '@vue/runtime-core'
2626
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
2727
import { hydrate, render } from '.'
@@ -136,9 +136,9 @@ export function defineCustomElement<
136136

137137
// overload 5: defining a custom element from the returned value of
138138
// `defineComponent`
139-
export function defineCustomElement(options: {
140-
new (...args: any[]): ComponentPublicInstance
141-
}): VueElementConstructor
139+
export function defineCustomElement<P>(
140+
options: DefineComponent<P, any, any, any>
141+
): VueElementConstructor<ExtractPropTypes<P>>
142142

143143
/*! #__NO_SIDE_EFFECTS__ */
144144
export function defineCustomElement(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy