Repository: vuejs/composition-api (ts)

Issue:
Incorrect type determining required props
I believe we have a bug with how we're determining required vs optional props...

https://github.com/vuejs/composition-api/blob/be9de86a248c8f5e8f52aec1beeee78cc2e3519a/src/component/componentProps.ts#L29-L31

The second half of this condition looks backwards. We should be flagging props as required when they extend `{ default: never }`, not `{ default: any }`. Having a default value means the prop _isn't_ required, correct?

To demonstrate the problem, create a component with the following prop...

```ts
foo: {
  type: String,
  default: 'asdf',
}
```

Then attempt to render that component without defining `foo`.

```
Type '{}' is not assignable to type '{ foo: string; } & {}'.
Property 'foo' is missing in type '{}' but required in type '{ foo: string; }'.
```

As you can see, our optional prop is incorrectly ending up on the required side of [this intersection type](https://github.com/vuejs/composition-api/blob/be9de86a248c8f5e8f52aec1beeee78cc2e3519a/src/component/componentProps.ts#L65-L66).

It looks like this bug also exists in 3.x. If this is correct and I'm not misunderstanding how `default` should be effecting prop types, let me know and I'll open a PR there as well!
https://github.com/vuejs/vue-next/blob/4a965802e883107a2af00301a59fb7f403b6acf7/packages/runtime-core/src/componentProps.ts#L70

Pull request:
fix(types): RequiredKeys type
Closes #654 

Patch:
diff --git a/src/component/componentProps.ts b/src/component/componentProps.ts
index d01ee3e..85199e7 100644
--- a/src/component/componentProps.ts
+++ b/src/component/componentProps.ts
@@ -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>>


Test patch:
diff --git a/test-dts/defineComponent.test-d.ts b/test-dts/defineComponent.test-d.ts
index bdd033c..3481e27 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 c41e08b..d35d628 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<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
       },
     })
@@ -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
       },