Skip to content

Commit

Permalink
fix: make js component $props optional
Browse files Browse the repository at this point in the history
close #1426
  • Loading branch information
johnsoncodehk committed Jun 12, 2022
1 parent ed4a940 commit ab5821b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vue-code-gen/src/generators/script.ts
Expand Up @@ -421,15 +421,15 @@ export function generate(
// fill $props
if (scriptSetupRanges.propsTypeArg) {
// NOTE: defineProps is inaccurate for $props
codeGen.addText(`$props: defineProps<`);
codeGen.addText(`$props: (await import('./__VLS_types')).makeOptional(defineProps<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
codeGen.addText(`>(),\n`);
codeGen.addText(`>()),\n`);
}
else if (scriptSetupRanges.propsRuntimeArg) {
// NOTE: defineProps is inaccurate for $props
codeGen.addText(`$props: defineProps(`);
codeGen.addText(`$props: (await import('./__VLS_types')).makeOptional(defineProps(`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
codeGen.addText(`),\n`);
codeGen.addText(`)),\n`);
}
// fill $emit
if (scriptSetupRanges.emitsAssignName) {
Expand Down
1 change: 1 addition & 0 deletions packages/vue-typescript/src/utils/localTypes.ts
Expand Up @@ -43,6 +43,7 @@ export declare function directiveFunction<T>(dir: T):
: T extends FunctionDirective<infer E, infer V> ? undefined extends V ? (value?: V) => void : (value: V) => void
: T;
export declare function withScope<T, K>(ctx: T, scope: K): ctx is T & K;
export declare function makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
export type ExtractComponentSlots<T> =
IsAny<T> extends true ? Record<string, any>
Expand Down

0 comments on commit ab5821b

Please sign in to comment.