Skip to content

Commit

Permalink
fix(types): defineCustomElement using defineComponent return type wit…
Browse files Browse the repository at this point in the history
…h emits (#7937)

close #7782
  • Loading branch information
rudyxu1102 authored Nov 10, 2023
1 parent 341b541 commit 5d932a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
25 changes: 23 additions & 2 deletions packages/dts-test/defineCustomElement.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { defineCustomElement } from 'vue'
import { expectType, describe } from './utils'
import {
defineCustomElement,
defineComponent,
type VueElementConstructor
} from 'vue'
import { expectType, describe, test } from './utils'

describe('inject', () => {
// with object inject
Expand Down Expand Up @@ -62,3 +66,20 @@ describe('inject', () => {
}
})
})

describe('defineCustomElement using defineComponent return type', () => {
test('with emits', () => {
const Comp1Vue = defineComponent({
props: {
a: String
},
emits: {
click: () => true
}
})
const Comp = defineCustomElement(Comp1Vue)
expectType<VueElementConstructor>(Comp)

expectType<string | undefined>(new Comp().a)
})
})
10 changes: 5 additions & 5 deletions packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ComponentOptionsWithObjectProps,
ComponentOptionsWithoutProps,
ComponentPropsOptions,
ComponentPublicInstance,
ComputedOptions,
EmitsOptions,
MethodOptions,
Expand All @@ -21,7 +20,8 @@ import {
ConcreteComponent,
ComponentOptions,
ComponentInjectOptions,
SlotsType
SlotsType,
DefineComponent
} from '@vue/runtime-core'
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
import { hydrate, render } from '.'
Expand Down Expand Up @@ -136,9 +136,9 @@ export function defineCustomElement<

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

/*! #__NO_SIDE_EFFECTS__ */
export function defineCustomElement(
Expand Down

0 comments on commit 5d932a8

Please sign in to comment.