1+ import type { VueCompilerOptions } from '../types' ;
12import { getSlotsPropertyName } from '../utils/shared' ;
23
3- export function generateGlobalTypes ( lib : string , target : number , strictTemplates : boolean ) {
4- const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${ strictTemplates ? '' : ' & Record<string, unknown>' } ` ;
4+ export function getGlobalTypesFileName ( options : VueCompilerOptions ) {
5+ return [
6+ options . lib ,
7+ options . target ,
8+ options . checkUnknownProps ,
9+ options . checkUnknownEvents ,
10+ options . checkUnknownComponents ,
11+ ] . map ( v => {
12+ if ( typeof v === 'boolean' ) {
13+ return v ? 1 : 0 ;
14+ }
15+ return v ;
16+ } ) . join ( '_' ) + '.d.ts' ;
17+ }
18+
19+ export function generateGlobalTypes ( options : VueCompilerOptions ) {
20+ const { lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents } = options ;
21+ const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${ checkUnknownProps ? '' : ' & Record<string, unknown>' } ` ;
522 let text = `` ;
623 if ( target < 3.5 ) {
724 text += `
@@ -49,7 +66,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
4966 N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
5067 N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
5168 N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
52- ${ strictTemplates ? '{}' : '{ [K in N0]: unknown }' } ;
69+ ${ checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }' } ;
5370 type __VLS_FunctionalComponentProps<T, K> =
5471 '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
5572 : T extends (props: infer P, ...args: any) => any ? P :
@@ -69,7 +86,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
6986 : __VLS_IsFunction<Events, CamelizedEvent> extends true
7087 ? { [K in onEvent]?: Events[CamelizedEvent] }
7188 : Props
72- )${ strictTemplates ? '' : ' & Record<string, unknown>' } ;
89+ )${ checkUnknownEvents ? '' : ' & Record<string, unknown>' } ;
7390 // fix https://github.com/vuejs/language-tools/issues/926
7491 type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
7592 type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -143,8 +160,8 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
143160 } & { props?: ${ fnPropsType } ; expose?(exposed: K): void; } }
144161 : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
145162 : T extends (...args: any) => any ? T
146- : (_: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } , ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${ strictTemplates ? '' : ' & Record<string, unknown>' } } };
147- function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (_: T${ strictTemplates ? '' : ' & Record<string, unknown>' } ) => void;
163+ : (_: {}${ checkUnknownProps ? '' : ' & Record<string, unknown>' } , ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${ checkUnknownProps ? '' : ' & Record<string, unknown>' } } };
164+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (_: T${ checkUnknownComponents ? '' : ' & Record<string, unknown>' } ) => void;
148165 function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
149166 function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
150167 function __VLS_tryAsConstant<const T>(t: T): T;
0 commit comments