Skip to content

Commit fd30217

Browse files
authored
fix(language-core): ensure to pass tsc on inline global types (#4782)
* fix: ensure to pass tsc on inline global types * fix: newLine
1 parent 2bb3cc1 commit fd30217

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

packages/language-core/lib/codegen/globalTypes.ts

+24-21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { endOfLine, newLine } from './common';
44
export function generateGlobalTypes(mode: 'global' | 'local', lib: string, target: number, strictTemplates: boolean) {
55
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
66

7+
let decl = '';
78
let str = '';
89
let globalComponentsType: string;
910

@@ -17,14 +18,16 @@ export function generateGlobalTypes(mode: 'global' | 'local', lib: string, targe
1718
globalComponentsType = `import('${lib}').GlobalComponents`;
1819
}
1920
else {
21+
decl = 'declare ';
22+
str += `// @ts-ignore${newLine}`;
2023
str += `const __VLS_globalComponents = { ...{} as import('${lib}').GlobalComponents }${endOfLine}`;
2124
globalComponentsType = `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents`;
2225
}
2326

2427
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;
2831
2932
type __VLS_IntrinsicElements = ${(
3033
target >= 3.3
@@ -88,40 +91,40 @@ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
8891
>;
8992
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
9093
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): [
9497
item: T[number],
9598
key: number,
9699
index: number,
97100
][];
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): [
99102
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
100103
key: number,
101104
index: undefined,
102105
][];
103106
// #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): [
105108
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
106109
key: number,
107110
index: undefined,
108111
][];
109-
function __VLS_getVForSourceType<T>(source: T): [
112+
${decl}function __VLS_getVForSourceType<T>(source: T): [
110113
item: T[keyof T],
111114
key: keyof T,
112115
index: number,
113116
][];
114117
// @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>>;
116119
// @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
119122
? T | __VLS_unknownDirective
120123
: 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):
125128
T extends new (...args: any) => any
126129
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
127130
attrs?: any,
@@ -131,14 +134,14 @@ function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any
131134
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
132135
: T extends (...args: any) => any ? T
133136
: (_: {}${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<
137140
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
138141
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
139142
>>;
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;
142145
`;
143146

144147
if (mode === 'global') {

0 commit comments

Comments
 (0)