Skip to content

Commit e339424

Browse files
authored
feat: support vue2 $scopedSlots (#819)
1 parent 9623a12 commit e339424

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/vscode-vue-languageservice/src/utils/localTypes.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ export function getVueLibraryName(isVue2: boolean) {
1010
return isVue2 ? '@vue/runtime-dom' : 'vue';
1111
}
1212

13+
export function getSlotsPropertyName(isVue2: boolean) {
14+
return isVue2 ? '$scopedSlots' : '$slots';
15+
}
16+
1317
export const typesFileName = '__VLS_types.ts';
1418

1519
export function getTypesCode(isVue2: boolean) {
1620
const libName = getVueLibraryName(isVue2);
21+
const slots = getSlotsPropertyName(isVue2);
1722
return `
1823
import * as vue from '${libName}';
1924
import type {
@@ -61,12 +66,12 @@ export declare function directiveFunction<T>(dir: T):
6166
6267
export type TemplateSlots<T> = T extends { __VLS_slots: infer S } ? S : {};
6368
export type HasTemplateSlotsType<T> = T extends { __VLS_slots: infer _ } ? true : false;
64-
export type HasScriptSlotsType<T> = T extends new (...args: any) => { $slots?: infer _ } ? true : false;
69+
export type HasScriptSlotsType<T> = T extends new (...args: any) => { ${slots}?: infer _ } ? true : false;
6570
export type DefaultSlots<W, R> = HasTemplateSlotsType<W> extends true ? {}
6671
: HasScriptSlotsType<R> extends true ? {}
6772
: Record<string, any>;
68-
export type SlotsComponent<T> = T extends new (...args: any) => { $slots?: infer S } ? T : new (...args: any) => { $slots: {} };
69-
export type ScriptSlots<T> = T extends { $slots?: infer S }
73+
export type SlotsComponent<T> = T extends new (...args: any) => { ${slots}?: infer S } ? T : new (...args: any) => { ${slots}: {} };
74+
export type ScriptSlots<T> = T extends { ${slots}?: infer S }
7075
? { [K in keyof S]-?: S[K] extends ((obj: infer O) => any) | undefined ? O : S[K] }
7176
: {};
7277

0 commit comments

Comments
 (0)