Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: support extends and mixins
  • Loading branch information
zcf0508 committed Dec 18, 2023
commit 29518ef9697cf0459e42e5e760a7be0e2783c695
30 changes: 29 additions & 1 deletion types/test/v3/define-component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ describe('emits', () => {
})

// should have `onXXX` props for emits
defineComponent({
const a = defineComponent({
props: {
bar: String
},
Expand All @@ -979,6 +979,34 @@ describe('emits', () => {
expectType<((n: number) => boolean) | undefined>(props.onFoo)
}
})

const b = defineComponent({
extends: a,
props: {
bar2: String
},
emits: {
foo2: (n: number) => n > 0
},
setup(props) {
expectType<((n: number) => boolean) | undefined>(props.onFoo)
}
})

defineComponent({
mixins: [a, b],
props: {
bar3: String
},
emits: {
foo3: (n: number) => n > 0
},
setup(props) {
expectType<((n: number) => boolean) | undefined>(props.onFoo)
expectType<((n: number) => boolean) | undefined>(props.onFoo2)
expectType<((n: number) => boolean) | undefined>(props.onFoo3)
}
})
})

// describe('componentOptions setup should be `SetupContext`', () => {
Expand Down
4 changes: 2 additions & 2 deletions types/v3-component-public-instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ComponentOptionsMixin,
ComponentOptionsBase
} from './v3-component-options'
import { EmitFn, EmitsOptions, EmitsToProps } from './v3-setup-context'
import { EmitFn, EmitsOptions } from './v3-setup-context'

/**
* Custom properties added to component instances in any way and can be accessed through `this`
Expand Down Expand Up @@ -150,7 +150,7 @@ export type ComponentPublicInstance<
>
> = Vue3Instance<
D,
P & EmitsToProps<E>,
P,
PublicProps,
E,
Defaults,
Expand Down
6 changes: 3 additions & 3 deletions types/v3-define-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
CreateComponentPublicInstance
} from './v3-component-public-instance'
import { Data, HasDefined } from './common'
import { EmitsOptions } from './v3-setup-context'
import { EmitsOptions, EmitsToProps } from './v3-setup-context'
import { CreateElement, RenderContext } from './umd'

export type DefineComponent<
Expand All @@ -31,9 +31,9 @@ export type DefineComponent<
E extends EmitsOptions = {},
EE extends string = string,
Props = Readonly<
PropsOrPropOptions extends ComponentPropsOptions
(PropsOrPropOptions extends ComponentPropsOptions
? ExtractPropTypes<PropsOrPropOptions>
: PropsOrPropOptions
: PropsOrPropOptions) & EmitsToProps<E>
>,
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
> = ComponentPublicInstanceConstructor<
Expand Down