Skip to content

Commit a5ace7f

Browse files
fix(types): Function PropType (#208) (#212)
* fix(types): Function PropType (#208) * revert style * revert style * revert style * rebase upstream branch * Update test/types/defineComponent.spec.ts * Update test/types/defineComponent.spec.ts * Update defineComponent.spec.ts Co-authored-by: Haoqun Jiang <[email protected]>
1 parent d001f06 commit a5ace7f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/component/componentProps.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export interface PropOptions<T = any, Required extends boolean = false> {
1515

1616
export type PropType<T> = PropConstructor<T> | PropConstructor<T>[];
1717

18-
type PropConstructor<T> = { new (...args: any[]): T & object } | { (): T };
18+
type PropConstructor<T> =
19+
| { new (...args: any[]): T & object }
20+
| { (): T }
21+
| { new (...args: string[]): Function };
1922

2023
type RequiredKeys<T, MakeDefaultRequired> = {
2124
[K in keyof T]: T[K] extends

test/types/defineComponent.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createComponent, defineComponent, createElement as h, ref, SetupContext } from '../../src';
1+
import { createComponent, defineComponent, createElement as h, ref, SetupContext, PropType } from '../../src';
22
import Router from 'vue-router';
33

44
const Vue = require('vue/dist/vue.common.js');
@@ -85,6 +85,26 @@ describe('defineComponent', () => {
8585
expect.assertions(3);
8686
});
8787

88+
it('custom props type function', () => {
89+
interface IPropsTypeFunction {
90+
fn: (arg: boolean) => void;
91+
}
92+
const App = defineComponent<IPropsTypeFunction>({
93+
props: {
94+
fn: Function as PropType<(arg: boolean) => void>,
95+
},
96+
setup(props, ctx) {
97+
type PropsType = typeof props;
98+
isTypeEqual<SetupContext, typeof ctx>(true);
99+
isSubType<PropsType, { fn: (arg: boolean) => void }>(true);
100+
isSubType<{ fn: (arg: boolean) => void }, PropsType>(true);
101+
return () => null;
102+
},
103+
});
104+
new Vue(App);
105+
expect.assertions(3);
106+
});
107+
88108
it('no props', () => {
89109
const App = defineComponent({
90110
setup(props, ctx) {

0 commit comments

Comments
 (0)