Skip to content

Commit

Permalink
fix(types): RequiredKeys type (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbedard committed Mar 11, 2021
1 parent be9de86 commit 0677a18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/component/componentProps.ts
Expand Up @@ -27,7 +27,7 @@ type PropConstructor<T> =
| { new (...args: string[]): Function }

type RequiredKeys<T> = {
[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<T> = Exclude<keyof T, RequiredKeys<T>>
Expand Down
8 changes: 4 additions & 4 deletions test-dts/defineComponent.test-d.ts
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions test/types/defineComponent.spec.ts
Expand Up @@ -58,8 +58,8 @@ describe('defineComponent', () => {
setup(props, ctx) {
type PropsType = typeof props
isTypeEqual<SetupContext, typeof ctx>(true)
isSubType<PropsType, { readonly b?: string; readonly a: number }>(true)
isSubType<{ readonly b?: string; readonly a: number }, PropsType>(true)
isSubType<PropsType, { readonly b?: string; readonly a?: number }>(true)
isSubType<{ readonly b?: string; readonly a?: number }, PropsType>(true)
return () => null
},
})
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit 0677a18

Please sign in to comment.