Skip to content

Commit 0677a18

Browse files
authored
fix(types): RequiredKeys type (#655)
1 parent be9de86 commit 0677a18

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/component/componentProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type PropConstructor<T> =
2727
| { new (...args: string[]): Function }
2828

2929
type RequiredKeys<T> = {
30-
[K in keyof T]: T[K] extends { required: true } | { default: any } ? K : never
30+
[K in keyof T]: T[K] extends { required: true } | { default: never } ? K : never
3131
}[keyof T]
3232

3333
type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>

test-dts/defineComponent.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('with object props', () => {
1313
a?: number | undefined
1414
b: string
1515
e?: Function
16-
bb: string
17-
bbb: string
16+
bb?: string
17+
bbb?: string
1818
cc?: string[] | undefined
1919
dd: { n: 1 }
2020
ee?: () => string
@@ -24,8 +24,8 @@ describe('with object props', () => {
2424
eee: () => { a: string }
2525
fff: (a: number, b: string) => { a: boolean }
2626
hhh: boolean
27-
ggg: 'foo' | 'bar'
28-
ffff: (a: number, b: string) => { a: boolean }
27+
ggg?: 'foo' | 'bar'
28+
ffff?: (a: number, b: string) => { a: boolean }
2929
validated?: string
3030
date: Date
3131
}

test/types/defineComponent.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ describe('defineComponent', () => {
5858
setup(props, ctx) {
5959
type PropsType = typeof props
6060
isTypeEqual<SetupContext, typeof ctx>(true)
61-
isSubType<PropsType, { readonly b?: string; readonly a: number }>(true)
62-
isSubType<{ readonly b?: string; readonly a: number }, PropsType>(true)
61+
isSubType<PropsType, { readonly b?: string; readonly a?: number }>(true)
62+
isSubType<{ readonly b?: string; readonly a?: number }, PropsType>(true)
6363
return () => null
6464
},
6565
})
@@ -191,12 +191,12 @@ describe('defineComponent', () => {
191191
setup(props) {
192192
type PropsType = typeof props
193193
isSubType<
194-
{ readonly foo: string; readonly bar: string; readonly zoo?: string },
194+
{ readonly foo: string; readonly bar?: string; readonly zoo?: string },
195195
PropsType
196196
>(true)
197197
isSubType<
198198
PropsType,
199-
{ readonly foo: string; readonly bar: string; readonly zoo?: string }
199+
{ readonly foo: string; readonly bar?: string; readonly zoo?: string }
200200
>(true)
201201
return () => null
202202
},

0 commit comments

Comments
 (0)