Skip to content

Commit 342cf3b

Browse files
committed
refactor(language-core): rename unknown props to __VLS_unknownProps for consistency
1 parent 5d841f4 commit 342cf3b

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export function getGlobalTypesFileName(options: VueCompilerOptions) {
1111
export function generateGlobalTypes(options: VueCompilerOptions) {
1212
const { lib, target, checkUnknownProps } = options;
1313

14-
const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${
15-
checkUnknownProps ? '' : ' & Record<string, unknown>'
16-
}`;
1714
let text = `// @ts-nocheck\nexport {};\n`;
1815
if (target < 3.5) {
1916
text += `
@@ -24,6 +21,8 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
2421
}
2522
text += `
2623
; declare global {
24+
var __VLS_unknownProps: ${checkUnknownProps ? '{}' : 'Record<string, unknown>'};
25+
2726
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
2827
const __VLS_unref: typeof import('${lib}').unref;
2928
const __VLS_placeholder: any;
@@ -32,7 +31,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
3231
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements`
3332
: `globalThis.JSX.IntrinsicElements`
3433
};
35-
var __VLS_CheckUnknownProps: ${checkUnknownProps ? '{}' : 'Record<string, unknown>'};
34+
3635
type __VLS_Elements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
3736
type __VLS_GlobalComponents = ${
3837
target >= 3.5
@@ -60,7 +59,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
6059
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
6160
: T extends (props: infer P, ...args: any) => any ? P
6261
: {};
63-
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => ${
62+
type __VLS_FunctionalComponent<T> = (props: (T extends { $props: infer Props } ? Props : {}) & typeof __VLS_unknownProps, ctx?: any) => ${
6463
target >= 3.3
6564
? `import('${lib}/jsx-runtime').JSX.Element`
6665
: `globalThis.JSX.Element`
@@ -69,7 +68,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
6968
attrs?: any;
7069
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
7170
emit?: T extends { $emit: infer Emit } ? Emit : {};
72-
props?: ${fnPropsType};
71+
props?: typeof props;
7372
expose?: (exposed: T) => void;
7473
};
7574
};

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ export function* generateScriptSetup(
9797
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
9898
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
9999
: `globalThis.JSX.IntrinsicAttributes`
100-
}${newLine}`
101-
+ ` & (typeof globalThis extends { __VLS_CheckUnknownProps: infer P } ? P : {})${endOfLine}`
100+
} & (typeof globalThis extends { __VLS_unknownProps: infer P } ? P : {})${endOfLine}`
102101
+ ` expose: (exposed: ${
103102
scriptSetupRanges.defineExpose
104103
? `import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<typeof __VLS_exposed>`

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
6464
"onUpdate:title"?: (value: string) => any;
6565
onBar?: (data: number) => any;
6666
}> & import("vue").PublicProps & (typeof globalThis extends {
67-
__VLS_CheckUnknownProps: infer P;
67+
__VLS_unknownProps: infer P;
6868
} ? P : {});
6969
expose: (exposed: import("vue").ShallowUnwrapRef<{
7070
baz: number;
@@ -97,7 +97,7 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
9797
"onUpdate:title"?: (value: string) => any;
9898
onBar?: (data: number) => any;
9999
}> & import("vue").PublicProps & (typeof globalThis extends {
100-
__VLS_CheckUnknownProps: infer P;
100+
__VLS_unknownProps: infer P;
101101
} ? P : {});
102102
expose: (exposed: import("vue").ShallowUnwrapRef<{
103103
baz: number;

0 commit comments

Comments
 (0)