Skip to content

Commit e9488af

Browse files
committed
Fix #3107
1 parent e4f0753 commit e9488af

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

server/src/services/typescriptService/bridge.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export const moduleName = 'vue-editor-bridge';
88
export const fileName = 'vue-temp/vue-editor-bridge.ts';
99

1010
const renderHelpers = `
11-
type ComponentListeners<T> = {
12-
[K in keyof T]?: ($event: T[K]) => any;
11+
type ComponentListeners<T, TH> = {
12+
[K in keyof T]?: (this: TH, $event: T[K]) => any;
1313
};
14-
export interface ${componentDataName}<T> {
14+
export interface ${componentDataName}<T, TH> {
1515
props: Record<string, any>;
16-
on: ComponentListeners<T>;
16+
on: ComponentListeners<T, TH>;
1717
directives: any[];
1818
}
1919
export declare const ${renderHelperName}: {
@@ -23,7 +23,7 @@ export declare const ${componentHelperName}: {
2323
<T>(
2424
vm: T,
2525
tag: string,
26-
data: ${componentDataName}<Record<string, any>> & ThisType<T>,
26+
data: ${componentDataName}<Record<string, any>, T> & ThisType<T>,
2727
children: any[]
2828
): any;
2929
};

server/src/services/typescriptService/preprocess.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function createUpdater(
119119
newText,
120120
sourceFile.languageVersion,
121121
true /* setParentNodes: Need this to walk the AST */,
122-
tsModule.ScriptKind.JS
122+
tsModule.ScriptKind.TS
123123
);
124124
// Assign version to the new template sourceFile to avoid re-processing
125125
// *internal* property
@@ -338,15 +338,15 @@ function convertChildComponentsInfoToSource(childComponents: ChildComponent[]) {
338338
});
339339

340340
src += `
341-
interface ${componentDataInterfaceName}<T> extends ${componentDataName}<T> {
341+
interface ${componentDataInterfaceName}<T, TH> extends ${componentDataName}<T, TH> {
342342
props: { ${propTypeStrings.join(', ')} }
343-
on: { ${onTypeStrings.join(', ')} } & { [K in keyof T]?: ($event: T[K]) => any; }
343+
on: { ${onTypeStrings.join(', ')} } & { [K in keyof T]?: (this: TH, $event: T[K]) => any; }
344344
}
345345
declare const ${componentHelperInterfaceName}: {
346346
<T>(
347347
vm: T,
348348
tag: string,
349-
data: ${componentDataInterfaceName}<Record<string, any>> & ThisType<T>,
349+
data: ${componentDataInterfaceName}<Record<string, any>, T> & ThisType<T>,
350350
children: any[]
351351
): any
352352
}`;

server/src/services/typescriptService/serviceHost.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export function getServiceHost(
310310
}
311311
return getScriptKind(tsModule, doc.languageId);
312312
} else if (isVirtualVueTemplateFile(fileName)) {
313-
return tsModule.ScriptKind.JS;
313+
return tsModule.ScriptKind.TS;
314314
} else {
315315
if (fileName === bridge.fileName) {
316316
return tsModule.ScriptKind.TS;

test/componentData/features/hover/basic.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('Should show hover info with component data', () => {
88
it('shows element description', async () => {
99
await testHover(docUri, position(2, 5), {
1010
contents: [
11-
'```ts\n(property) __vlsComponentData<Record<string, any>>.props: Record<string, any>\n```\nA foo tag'
11+
'```ts\n(property) __vlsComponentData<Record<string, any>, CombinedVueInstance<{ noop(): void; } & Record<never, any> & Vue, object, object, object, Record<never, any>>>.props: Record<string, any>\n```\nA foo tag'
1212
],
1313
range: sameLineRange(2, 5, 12)
1414
});
@@ -37,7 +37,9 @@ describe('Should show hover info with component data', () => {
3737

3838
it('shows attribute description for html event handler', async () => {
3939
await testHover(docUri, position(4, 26), {
40-
contents: ['```ts\n(property) "error": ($event: any) => () => void\n```'],
40+
contents: [
41+
'```ts\n(property) "error": (this: CombinedVueInstance<{\n noop(): void;\n} & Record<never, any> & Vue, object, object, object, Record<never, any>>, $event: any) => () => void\n```'
42+
],
4143
range: sameLineRange(4, 26, 31)
4244
});
4345
});

test/interpolation/features/diagnostics/basic.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ describe('Should find template-diagnostics in <template> region', () => {
264264
'issue-1745-duplicate-event-with-modifiers.vue',
265265
'issue-2254.vue',
266266
'issue-2258.vue',
267-
'optional-in-template.vue'
267+
'optional-in-template.vue',
268+
'issue-3107.vue'
268269
];
269270

270271
noErrorTests.forEach(t => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<button @click="page = newPage">
3+
Switch to page {{ newPage }}
4+
</button>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data() {
10+
return {
11+
page: "home",
12+
newPage: "products",
13+
}
14+
}
15+
}
16+
</script>

0 commit comments

Comments
 (0)