10000 fix: allow slots to have no arguments by so1ve · Pull Request #3376 · vuejs/language-tools · GitHub
[go: up one dir, main page]

Skip to content

fix: allow slots to have no arguments #3376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
patch the consumer side instead of the definer side
  • Loading branch information
johnsoncodehk committed Jul 13, 2023
commit 895cdd778412c0b5bcd65c10cdb8ca18dc95d7eb
4 changes: 2 additions & 2 deletions packages/vue-language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
generateConstNameOption();

if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) {
codes.push(`var __VLS_slots!: __VLS_NormalizeSlots<`);
codes.push(`var __VLS_slots!: `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
codes.push('>;\n');
codes.push(';\n');
};

codes.push(`function __VLS_template() {\n`);
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,14 +1596,15 @@ export function generate(

if (hasScriptSetupSlots) {
codes.push(
'__VLS_normalizeSlot(',
['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly],
'__VLS_slots[',
['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly],
slotNameExpNode?.content ?? `('${getSlotName()}' as const)`,
['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly],
']',
['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly],
'?.(',
')?.(',
['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly],
'{\n',
);
Expand Down
4 changes: 1 addition & 3 deletions packages/vue-language-core/src/utils/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K
T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
>;
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
type __VLS_NormalizeSlots<T> = {
[K in keyof T]: T[K] extends () => infer R ? (arg: any) => R : T[K]
}

declare function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
declare function __VLS_componentProps<T, K>(comp: T, fnReturn: K):
__VLS_PickNotAny<K, {}> extends { __ctx: { props: infer P } } ? NonNullable<P>
: T extends (props: infer P, ...args: any) => any ? NonNullable<P> :
Expand Down
0