1
1
import type { VueCompilerOptions } from '../types' ;
2
2
import { getSlotsPropertyName } from '../utils/shared' ;
3
3
4
- export function getGlobalTypesFileName ( {
5
- lib,
6
- target,
7
- checkUnknownProps,
8
- checkUnknownEvents,
9
- checkUnknownComponents,
10
- } : VueCompilerOptions ) {
4
+ export function getGlobalTypesFileName ( options : VueCompilerOptions ) {
11
5
return [
12
- lib ,
13
- target ,
14
- checkUnknownProps ,
15
- checkUnknownEvents ,
16
- checkUnknownComponents ,
6
+ options . lib ,
7
+ options . target ,
8
+ options . checkUnknownProps ,
17
9
] . map ( v => ( typeof v === 'boolean' ? Number ( v ) : v ) ) . join ( '_' ) + '.d.ts' ;
18
10
}
19
11
20
- export function generateGlobalTypes ( {
21
- lib,
22
- target,
23
- checkUnknownProps,
24
- checkUnknownEvents,
25
- checkUnknownComponents,
26
- } : VueCompilerOptions ) {
12
+ export function generateGlobalTypes ( options : VueCompilerOptions ) {
13
+ const { lib, target, checkUnknownProps } = options ;
14
+
27
15
const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${
28
16
checkUnknownProps ? '' : ' & Record<string, unknown>'
29
17
} `;
@@ -69,7 +57,7 @@ export function generateGlobalTypes({
69
57
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
70
58
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
71
59
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
72
- ${ checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }' } ;
60
+ { };
73
61
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
74
62
? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
75
63
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
@@ -80,12 +68,12 @@ export function generateGlobalTypes({
80
68
: {};
81
69
type __VLS_FunctionalComponent<T> = (props: ${ fnPropsType } , ctx?: any) => __VLS_Element & {
82
70
__ctx?: {
83
- attrs?: any,
84
- slots?: T extends { ${ getSlotsPropertyName ( target ) } : infer Slots } ? Slots : Record<string, any>,
85
- emit?: T extends { $emit: infer Emit } ? Emit : {},
86
- props?: ${ fnPropsType } ,
87
- expose?: (exposed: T) => void,
88
- }
71
+ attrs?: any;
72
+ slots?: T extends { ${ getSlotsPropertyName ( target ) } : infer Slots } ? Slots : Record<string, any>;
73
+ emit?: T extends { $emit: infer Emit } ? Emit : {};
74
+ props?: ${ fnPropsType } ;
75
+ expose?: (exposed: T) => void;
76
+ };
89
77
};
90
78
type __VLS_IsFunction<T, K> = K extends keyof T
91
79
? __VLS_IsAny<T[K]> extends false
@@ -94,15 +82,19 @@ export function generateGlobalTypes({
94
82
: true
95
83
: false
96
84
: false;
97
- type __VLS_NormalizeComponentEvent<Props, Emits, onEvent extends keyof Props, Event extends keyof Emits, CamelizedEvent extends keyof Emits> = (
98
- __VLS_IsFunction<Props, onEvent> extends true
99
- ? Props
100
- : __VLS_IsFunction<Emits, Event> extends true
101
- ? { [K in onEvent]?: Emits[Event] }
102
- : __VLS_IsFunction<Emits, CamelizedEvent> extends true
103
- ? { [K in onEvent]?: Emits[CamelizedEvent] }
104
- : Props
105
- )${ checkUnknownEvents ? '' : ' & Record<string, unknown>' } ;
85
+ type __VLS_NormalizeComponentEvent<
86
+ Props,
87
+ Emits,
88
+ onEvent extends keyof Props,
89
+ Event extends keyof Emits,
90
+ CamelizedEvent extends keyof Emits,
91
+ > = __VLS_IsFunction<Props, onEvent> extends true
92
+ ? Props
93
+ : __VLS_IsFunction<Emits, Event> extends true
94
+ ? { [K in onEvent]?: Emits[Event] }
95
+ : __VLS_IsFunction<Emits, CamelizedEvent> extends true
96
+ ? { [K in onEvent]?: Emits[CamelizedEvent] }
97
+ : Props;
106
98
// fix https://github.com/vuejs/language-tools/issues/926
107
99
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
108
100
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -174,7 +166,7 @@ export function generateGlobalTypes({
174
166
: __VLS_FunctionalComponent<{}>;
175
167
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
176
168
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${
177
- checkUnknownComponents ? '' : ' & Record<string, unknown>'
169
+ checkUnknownProps ? '' : ' & Record<string, unknown>'
178
170
} ) => void;
179
171
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
180
172
function __VLS_tryAsConstant<const T>(t: T): T;
0 commit comments