Skip to content

Commit 26d99fd

Browse files
authored
test(require-explicit-slots): import slot type (#2786)
1 parent 3d9e15e commit 26d99fd

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/fixtures/typescript/src/test01.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ export type Props2 = {
1818
h?: string[]
1919
i?: readonly string[]
2020
}
21+
22+
export type Slots1 = {
23+
default(props: { msg: string }): any
24+
foo(props: { msg: string }): any
25+
}

tests/lib/rules/require-explicit-slots.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
const RuleTester = require('../../eslint-compat').RuleTester
88
const rule = require('../../../lib/rules/require-explicit-slots')
9+
const {
10+
getTypeScriptFixtureTestOptions
11+
} = require('../../test-utils/typescript')
912

1013
const tester = new RuleTester({
1114
languageOptions: {
@@ -276,6 +279,21 @@ tester.run('require-explicit-slots', rule, {
276279
})
277280
</script>`
278281
},
282+
{
283+
filename: 'test.vue',
284+
code: `
285+
<template>
286+
<div>
287+
<slot></slot>
288+
<slot name="foo"></slot>
289+
</div>
290+
</template>
291+
<script setup lang="ts">
292+
import type {Slots1 as Slots} from './test01'
293+
defineSlots<Slots>()
294+
</script>`,
295+
...getTypeScriptFixtureTestOptions()
296+
},
279297
{
280298
filename: 'test.vue',
281299
code: `
@@ -656,6 +674,28 @@ tester.run('require-explicit-slots', rule, {
656674
}
657675
]
658676
},
677+
{
678+
filename: 'test.vue',
679+
code: `
680+
<template>
681+
<div>
682+
<slot name="foo"></slot>
683+
<slot name="bar"></slot>
684+
</div>
685+
</template>
686+
<script setup lang="ts">
687+
import type {Slots1 as Slots} from './test01'
688+
defineSlots<Slots>()
689+
</script>`,
690+
errors: [
691+
{
692+
message: 'Slots must be explicitly defined.',
693+
line: 5,
694+
column: 11
695+
}
696+
],
697+
...getTypeScriptFixtureTestOptions()
698+
},
659699
{
660700
// ignore attribute binding except string literal
661701
filename: 'test.vue',

0 commit comments

Comments
 (0)