diff --git a/src/component/componentProps.ts b/src/component/componentProps.ts index d01ee3ed..85199e79 100644 --- a/src/component/componentProps.ts +++ b/src/component/componentProps.ts @@ -27,7 +27,7 @@ type PropConstructor = | { new (...args: string[]): Function } type RequiredKeys = { - [K in keyof T]: T[K] extends { required: true } | { default: any } ? K : never + [K in keyof T]: T[K] extends { required: true } | { default: never } ? K : never }[keyof T] type OptionalKeys = Exclude> diff --git a/test-dts/defineComponent.test-d.ts b/test-dts/defineComponent.test-d.ts index bdd033cc..3481e274 100644 --- a/test-dts/defineComponent.test-d.ts +++ b/test-dts/defineComponent.test-d.ts @@ -13,8 +13,8 @@ describe('with object props', () => { a?: number | undefined b: string e?: Function - bb: string - bbb: string + bb?: string + bbb?: string cc?: string[] | undefined dd: { n: 1 } ee?: () => string @@ -24,8 +24,8 @@ describe('with object props', () => { eee: () => { a: string } fff: (a: number, b: string) => { a: boolean } hhh: boolean - ggg: 'foo' | 'bar' - ffff: (a: number, b: string) => { a: boolean } + ggg?: 'foo' | 'bar' + ffff?: (a: number, b: string) => { a: boolean } validated?: string date: Date } diff --git a/test/types/defineComponent.spec.ts b/test/types/defineComponent.spec.ts index c41e08b1..d35d6281 100644 --- a/test/types/defineComponent.spec.ts +++ b/test/types/defineComponent.spec.ts @@ -58,8 +58,8 @@ describe('defineComponent', () => { setup(props, ctx) { type PropsType = typeof props isTypeEqual(true) - isSubType(true) - isSubType<{ readonly b?: string; readonly a: number }, PropsType>(true) + isSubType(true) + isSubType<{ readonly b?: string; readonly a?: number }, PropsType>(true) return () => null }, }) @@ -191,12 +191,12 @@ describe('defineComponent', () => { setup(props) { type PropsType = typeof props isSubType< - { readonly foo: string; readonly bar: string; readonly zoo?: string }, + { readonly foo: string; readonly bar?: string; readonly zoo?: string }, PropsType >(true) isSubType< PropsType, - { readonly foo: string; readonly bar: string; readonly zoo?: string } + { readonly foo: string; readonly bar?: string; readonly zoo?: string } >(true) return () => null },