@@ -4,6 +4,7 @@ import { endOfLine, newLine } from './common';
4
4
export function generateGlobalTypes ( mode : 'global' | 'local' , lib : string , target : number , strictTemplates : boolean ) {
5
5
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${ strictTemplates ? '' : ' & Record<string, unknown>' } ` ;
6
6
7
+ let decl = '' ;
7
8
let str = '' ;
8
9
let globalComponentsType : string ;
9
10
@@ -17,14 +18,16 @@ export function generateGlobalTypes(mode: 'global' | 'local', lib: string, targe
17
18
globalComponentsType = `import('${ lib } ').GlobalComponents` ;
18
19
}
19
20
else {
21
+ decl = 'declare ' ;
22
+ str += `// @ts-ignore${ newLine } ` ;
20
23
str += `const __VLS_globalComponents = { ...{} as import('${ lib } ').GlobalComponents }${ endOfLine } ` ;
21
24
globalComponentsType = `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents` ;
22
25
}
23
26
24
27
str += `
25
- const __VLS_intrinsicElements: __VLS_IntrinsicElements;
26
- const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
27
- const __VLS_unref: typeof import('${ lib } ').unref;
28
+ ${ decl } const __VLS_intrinsicElements: __VLS_IntrinsicElements;
29
+ ${ decl } const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
30
+ ${ decl } const __VLS_unref: typeof import('${ lib } ').unref;
28
31
29
32
type __VLS_IntrinsicElements = ${ (
30
33
target >= 3.3
@@ -88,40 +91,40 @@ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
88
91
>;
89
92
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
90
93
91
- function __VLS_getVForSourceType(source: number): [number, number, number][];
92
- function __VLS_getVForSourceType(source: string): [string, number, number][];
93
- function __VLS_getVForSourceType<T extends any[]>(source: T): [
94
+ ${ decl } function __VLS_getVForSourceType(source: number): [number, number, number][];
95
+ ${ decl } function __VLS_getVForSourceType(source: string): [string, number, number][];
96
+ ${ decl } function __VLS_getVForSourceType<T extends any[]>(source: T): [
94
97
item: T[number],
95
98
key: number,
96
99
index: number,
97
100
][];
98
- function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
101
+ ${ decl } function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
99
102
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
100
103
key: number,
101
104
index: undefined,
102
105
][];
103
106
// #3845
104
- function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
107
+ ${ decl } function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
105
108
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
106
109
key: number,
107
110
index: undefined,
108
111
][];
109
- function __VLS_getVForSourceType<T>(source: T): [
112
+ ${ decl } function __VLS_getVForSourceType<T>(source: T): [
110
113
item: T[keyof T],
111
114
key: keyof T,
112
115
index: number,
113
116
][];
114
117
// @ts-ignore
115
- function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
118
+ ${ decl } function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
116
119
// @ts-ignore
117
- function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
118
- function __VLS_directiveAsFunction<T extends import('${ lib } ').Directive>(dir: T): T extends (...args: any) => any
120
+ ${ decl } function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
121
+ ${ decl } function __VLS_directiveAsFunction<T extends import('${ lib } ').Directive>(dir: T): T extends (...args: any) => any
119
122
? T | __VLS_unknownDirective
120
123
: NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
121
- function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
122
- function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
123
- function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
124
- function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
124
+ ${ decl } function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
125
+ ${ decl } function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
126
+ ${ decl } function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
127
+ ${ decl } function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
125
128
T extends new (...args: any) => any
126
129
? (props: ${ fnPropsType } , ctx?: any) => __VLS_Element & { __ctx?: {
127
130
attrs?: any,
@@ -131,14 +134,14 @@ function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any
131
134
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
132
135
: T extends (...args: any) => any ? T
133
136
: (_: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } , ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } } };
134
- function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${ strictTemplates ? '' : ' & Record<string, unknown>' } ) => void;
135
- function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
136
- function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
137
+ ${ decl } function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${ strictTemplates ? '' : ' & Record<string, unknown>' } ) => void;
138
+ ${ decl } function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
139
+ ${ decl } function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
137
140
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
138
141
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
139
142
>>;
140
- function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
141
- function __VLS_tryAsConstant<const T>(t: T): T;
143
+ ${ decl } function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
144
+ ${ decl } function __VLS_tryAsConstant<const T>(t: T): T;
142
145
` ;
143
146
144
147
if ( mode === 'global' ) {
0 commit comments