Skip to content

Commit

Permalink
fix(types): respect props with default on instance type when using __…
Browse files Browse the repository at this point in the history
…typeProps
  • Loading branch information
yyx990803 committed Jun 5, 2024
1 parent cd0ea0d commit 96e4738
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1972,3 +1972,24 @@ createApp({}).component(
},
}),
)

const Comp = defineComponent({
props: {
actionText: {
type: {} as PropType<string>,
default: 'Become a sponsor',
},
},
__typeProps: {} as {
actionText?: string
},
})

const instance = new Comp()
function expectString(s: string) {}
// instance prop with default should be non-null
expectString(instance.actionText)

// public prop on $props should be optional
// @ts-expect-error
expectString(instance.$props.actionText)
8 changes: 6 additions & 2 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export type ComponentPublicInstance<
C extends ComputedOptions = {},
M extends MethodOptions = {},
E extends EmitsOptions = {},
PublicProps = P,
PublicProps = {},
Defaults = {},
MakeDefaultsOptional extends boolean = false,
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
Expand Down Expand Up @@ -323,7 +323,11 @@ export type ComponentPublicInstance<
options?: WatchOptions,
): WatchStopHandle
} & ExposedKeys<
IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &
IfAny<
P,
P,
Readonly<Defaults> & Omit<P, keyof ShallowUnwrapRef<B> | keyof Defaults>
> &
ShallowUnwrapRef<B> &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &
Expand Down

0 comments on commit 96e4738

Please sign in to comment.