Skip to content

Commit 2cc52bd

Browse files
committed
fixes
1 parent f9ece30 commit 2cc52bd

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
121121
: T extends (...args: any) => any ? T
122122
: (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
123123
declare function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
124-
declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
124+
declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
125125
declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
126126
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
127127
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any

packages/language-core/lib/parsers/scriptSetupRanges.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export function parseScriptSetupRanges(
5050
name?: string;
5151
define?: ReturnType<typeof parseDefineFunction>;
5252
}[] = [];
53-
5453
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
5554
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
5655
const defineProp: {
@@ -63,11 +62,12 @@ export function parseScriptSetupRanges(
6362
required: boolean;
6463
isModel?: boolean;
6564
}[] = [];
66-
const bindings = parseBindingRanges(ts, ast);
6765
const text = ast.text;
6866
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
6967
const importComponentNames = new Set<string>();
7068

69+
let bindings = parseBindingRanges(ts, ast);
70+
7171
ts.forEachChild(ast, node => {
7272
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
7373
if (
@@ -102,6 +102,11 @@ export function parseScriptSetupRanges(
102102
});
103103
ts.forEachChild(ast, child => visitNode(child, [ast]));
104104

105+
bindings = bindings.filter(range => {
106+
const name = ast.text.substring(range.start, range.end);
107+
return templateRefs.every(ref => ref.name !== name);
108+
});
109+
105110
return {
106111
leadingCommentEndOffset,
107112
importSectionEndOffset,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
declare module 'vue' {
1+
declare module 'vue3.5' {
22
export interface GlobalComponents {
33
Generic: typeof import('./generic.vue')['default'];
44
}
55
}
6+
7+
export { };

test-workspace/tsc/passedFixtures/vue3.5/templateRef/template-ref.vue

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ import { useTemplateRef } from 'vue';
33
import { exactType } from '../../shared';
44
55
const comp1 = useTemplateRef('generic');
6+
if (comp1.value) {
7+
exactType(comp1.value.foo, 1)
8+
}
69
710
const comp2 = useTemplateRef('v-for');
8-
if (comp2.value) exactType(comp2.value[0]?.foo, {} as number | undefined);
11+
if (comp2.value) {
12+
exactType(comp2.value[0]?.foo, {} as number | undefined);
13+
}
914
1015
const comp3 = useTemplateRef('a');
11-
if (comp3.value) exactType(comp3.value?.href, {} as string | undefined);
16+
if (comp3.value) {
17+
exactType(comp3.value.href, {} as string | undefined);
18+
}
1219
</script>
1320

1421
<template>
1522
<Generic ref="generic" :foo="1"></Generic>
1623

17-
{{ exactType(comp1.foo, 1) }}
18-
1924
<Generic v-for="i in 4" ref="v-for" :foo="i"></Generic>
2025

2126
<a ref="a"></a>

0 commit comments

Comments
 (0)