Skip to content

Commit eeff860

Browse files
committed
chore: use experimentalExposeScriptSetupContext for vue-tsc
This new option allows a better typechecking of components that expose variables. See vuejs/language-tools#805 Refs #972 as this partially fixes it
1 parent 36c3d4f commit eeff860

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

tests/emit.spec.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
DefineComponent,
32
defineComponent,
43
FunctionalComponent,
54
getCurrentInstance,
@@ -346,16 +345,23 @@ describe('emitted', () => {
346345
expect(wrapper.emitted('click')).toHaveLength(1)
347346
})
348347

349-
it.each([EmitsEventSFC, EmitsEventScriptSetup] as DefineComponent[])(
350-
'captures emitted events',
351-
async (component) => {
352-
const wrapper = mount(component)
353-
await wrapper.trigger('click')
348+
it('captures emitted events in SFC', async () => {
349+
const wrapper = mount(EmitsEventSFC)
350+
await wrapper.trigger('click')
354351

355-
expect(wrapper.emitted().click).toHaveLength(1)
356-
expect(wrapper.emitted().bar).toHaveLength(2)
357-
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
358-
expect(wrapper.emitted().bar[1]).toEqual(['click'])
359-
}
360-
)
352+
expect(wrapper.emitted().click).toHaveLength(1)
353+
expect(wrapper.emitted().bar).toHaveLength(2)
354+
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
355+
expect(wrapper.emitted().bar[1]).toEqual(['click'])
356+
})
357+
358+
it('captures emitted events in script setup', async () => {
359+
const wrapper = mount(EmitsEventScriptSetup)
360+
await wrapper.trigger('click')
361+
362+
expect(wrapper.emitted().click).toHaveLength(1)
363+
expect(wrapper.emitted().bar).toHaveLength(2)
364+
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
365+
expect(wrapper.emitted().bar[1]).toEqual(['click'])
366+
})
361367
})

tests/expose.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ describe('expose', () => {
2525
const wrapper = mount(DefineExposeWithRenderFunction)
2626

2727
// other is exposed vie `expose`
28+
// @ts-ignore upstream issue, see https://github.com/vuejs/vue-next/issues/4397#issuecomment-957613874
2829
expect(wrapper.vm.other).toBe('other')
2930
// can't access `msg` as it is not exposed
3031
// and we are in a component with a setup returning a render function
31-
expect(wrapper.vm.msg).toBeUndefined()
32+
expect((wrapper.vm as unknown as { msg: undefined }).msg).toBeUndefined()
3233
})
3334

3435
it('access vm with <script setup> and defineExpose()', async () => {

tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"tests",
2323
"src",
2424
"types"
25-
]
25+
],
26+
"vueCompilerOptions": {
27+
"experimentalExposeScriptSetupContext": true
28+
}
2629
}

tsconfig.volar.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
"compilerOptions": {
44
"lib": ["DOM", "ES2020"],
55
"skipLibCheck": true
6-
},
7-
"exclude": ["tests/expose.spec.ts"]
6+
}
87
}

0 commit comments

Comments
 (0)