1
1
import { getSlotsPropertyName } from '../utils/shared' ;
2
+ import { endOfLine , newLine } from './common' ;
2
3
3
- export function generateGlobalTypes ( lib : string , target : number , strictTemplates : boolean ) {
4
+ export function generateGlobalTypes ( mode : 'global' | 'local' , lib : string , target : number , strictTemplates : boolean ) {
4
5
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${ strictTemplates ? '' : ' & Record<string, unknown>' } ` ;
5
- return `// @ts-nocheck
6
6
7
- const __VLS_globalComponents = { ...{} as import(' ${ lib } ').GlobalComponents } ;
7
+ let str = '' ;
8
8
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 };
11
21
12
22
type __VLS_IntrinsicElements = ${ (
13
23
target >= 3.3
@@ -21,8 +31,8 @@ type __VLS_Element = ${(
21
31
) }
22
32
type __VLS_GlobalComponents = ${ (
23
33
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'>;`
26
36
) }
27
37
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
28
38
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
@@ -71,40 +81,40 @@ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
71
81
>;
72
82
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
73
83
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): [
77
87
item: T[number],
78
88
key: number,
79
89
index: number,
80
90
][];
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): [
82
92
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
83
93
key: number,
84
94
index: undefined,
85
95
][];
86
96
// #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): [
88
98
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
89
99
key: number,
90
100
index: undefined,
91
101
][];
92
- declare function __VLS_getVForSourceType<T>(source: T): [
102
+ function __VLS_getVForSourceType<T>(source: T): [
93
103
item: T[keyof T],
94
104
key: keyof T,
95
105
index: number,
96
106
][];
97
107
// @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>>;
99
109
// @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
102
112
? T | __VLS_unknownDirective
103
113
: 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):
108
118
T extends new (...args: any) => any
109
119
? (props: ${ fnPropsType } , ctx?: any) => __VLS_Element & { __ctx?: {
110
120
attrs?: any,
@@ -114,13 +124,18 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
114
124
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
115
125
: T extends (...args: any) => any ? T
116
126
: (_: {}${ 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<
120
130
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
121
131
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
122
132
>>;
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;
125
135
` ;
136
+
137
+ if ( mode === 'global' ) {
138
+ str += `}${ newLine } ` ;
139
+ }
140
+ return str ;
126
141
} ;
0 commit comments