11import { getSlotsPropertyName } from '../utils/shared' ;
2+ import { endOfLine , newLine } from './common' ;
23
3- export function generateGlobalTypes ( lib : string , target : number , strictTemplates : boolean ) {
4+ export function generateGlobalTypes ( mode : 'global' | 'local' , lib : string , target : number , strictTemplates : boolean ) {
45 const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${ strictTemplates ? '' : ' & Record<string, unknown>' } ` ;
5- return `// @ts-nocheck
66
7- const __VLS_globalComponents = { ...{} as import(' ${ lib } ').GlobalComponents } ;
7+ let str = '' ;
88
9- declare const __VLS_intrinsicElements: __VLS_IntrinsicElements;
10- declare const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
9+ if ( mode === 'global' ) {
10+ str += `// @ts-nocheck${ newLine } ` ;
11+ str += `export {}${ endOfLine } ` ;
12+ str += `declare module '${ lib } ' {${ newLine } ` ;
13+ str += ` export interface GlobalComponents { }${ newLine } ` ;
14+ str += `}${ newLine } ` ;
15+ str += `declare global {${ newLine } ` ;
16+ }
17+
18+ str += `
19+ const __VLS_intrinsicElements: __VLS_IntrinsicElements;
20+ const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
1121
1222type __VLS_IntrinsicElements = ${ (
1323 target >= 3.3
@@ -21,8 +31,8 @@ type __VLS_Element = ${(
2131 ) }
2232type __VLS_GlobalComponents = ${ (
2333 target >= 3.5
24- ? `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents ;`
25- : `(void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents) & Pick<typeof import('${ lib } '), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`
34+ ? `import('vue').GlobalComponents ;`
35+ : `import('vue').GlobalComponents & Pick<typeof import('${ lib } '), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`
2636 ) }
2737type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
2838type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
@@ -71,40 +81,40 @@ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
7181>;
7282type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
7383
74- declare function __VLS_getVForSourceType(source: number): [number, number, number][];
75- declare function __VLS_getVForSourceType(source: string): [string, number, number][];
76- declare function __VLS_getVForSourceType<T extends any[]>(source: T): [
84+ function __VLS_getVForSourceType(source: number): [number, number, number][];
85+ function __VLS_getVForSourceType(source: string): [string, number, number][];
86+ function __VLS_getVForSourceType<T extends any[]>(source: T): [
7787 item: T[number],
7888 key: number,
7989 index: number,
8090][];
81- declare function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
91+ function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
8292 item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
8393 key: number,
8494 index: undefined,
8595][];
8696// #3845
87- declare function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
97+ function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
8898 item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
8999 key: number,
90100 index: undefined,
91101][];
92- declare function __VLS_getVForSourceType<T>(source: T): [
102+ function __VLS_getVForSourceType<T>(source: T): [
93103 item: T[keyof T],
94104 key: keyof T,
95105 index: number,
96106][];
97107// @ts-ignore
98- declare function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
108+ function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
99109// @ts-ignore
100- declare function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
101- declare function __VLS_directiveAsFunction<T extends import('${ lib } ').Directive>(dir: T): T extends (...args: any) => any
110+ function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
111+ function __VLS_directiveAsFunction<T extends import('${ lib } ').Directive>(dir: T): T extends (...args: any) => any
102112 ? T | __VLS_unknownDirective
103113 : NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
104- declare function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
105- declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
106- declare function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
107- declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
114+ function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
115+ function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
116+ function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
117+ function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
108118 T extends new (...args: any) => any
109119 ? (props: ${ fnPropsType } , ctx?: any) => __VLS_Element & { __ctx?: {
110120 attrs?: any,
@@ -114,13 +124,18 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
114124 : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
115125 : T extends (...args: any) => any ? T
116126 : (_: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } , ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } } };
117- declare function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${ strictTemplates ? '' : ' & Record<string, unknown>' } ) => void;
118- declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
119- declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
127+ function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${ strictTemplates ? '' : ' & Record<string, unknown>' } ) => void;
128+ function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
129+ function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
120130 '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
121131 , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
122132>>;
123- declare function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
124- declare function __VLS_tryAsConstant<const T>(t: T): T;
133+ function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
134+ function __VLS_tryAsConstant<const T>(t: T): T;
125135` ;
136+
137+ if ( mode === 'global' ) {
138+ str += `}${ newLine } ` ;
139+ }
140+ return str ;
126141} ;
0 commit comments