Skip to content

Commit e2dc246

Browse files
committed
types(runtime-core): add d.ts tests for app.use()
1 parent 47dbc22 commit e2dc246

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test-dts/appUse.test-d.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { createApp } from './index'
2+
3+
type App = ReturnType<typeof createApp>
4+
5+
type PluginAOptionType = {
6+
option1?: string
7+
option2: number
8+
option3: boolean
9+
}
10+
11+
const PluginA = {
12+
install(app: App, ...options: PluginAOptionType[]) {
13+
options[0].option1
14+
options[0].option2
15+
options[0].option3
16+
}
17+
}
18+
19+
const PluginB = {
20+
install(app: App) {}
21+
}
22+
23+
const PluginC = (app: App, ...options: string[]) => {}
24+
25+
createApp({})
26+
.use(PluginA)
27+
// @ts-expect-error option2 and option3 (required) missing
28+
.use(PluginA, {})
29+
// @ts-expect-error type mismatch
30+
.use(PluginA, true)
31+
// @ts-expect-error type mismatch
32+
.use(PluginA, undefined)
33+
// @ts-expect-error type mismatch
34+
.use(PluginA, null)
35+
// @ts-expect-error type mismatch
36+
.use(PluginA, 'foo')
37+
// @ts-expect-error type mismatch
38+
.use(PluginA, 1)
39+
.use(PluginA, { option2: 1, option3: true })
40+
.use(PluginA, { option1: 'foo', option2: 1, option3: true })
41+
42+
// @ts-expect-error option2 (required) missing
43+
.use(PluginA, { option3: true })
44+
45+
.use(PluginB)
46+
// @ts-expect-error unexpected plugin option
47+
.use(PluginB, {})
48+
// @ts-expect-error unexpected plugin option
49+
.use(PluginB, true)
50+
// @ts-expect-error unexpected plugin option
51+
.use(PluginB, undefined)
52+
// @ts-expect-error unexpected plugin option
53+
.use(PluginB, null)
54+
// @ts-expect-error type mismatch
55+
.use(PluginB, 'foo')
56+
// @ts-expect-error type mismatch
57+
.use(PluginB, 1)
58+
59+
.use(PluginC)
60+
// @ts-expect-error unexpected plugin option
61+
.use(PluginC, {})
62+
// @ts-expect-error unexpected plugin option
63+
.use(PluginC, true)
64+
// @ts-expect-error unexpected plugin option
65+
.use(PluginC, undefined)
66+
// @ts-expect-error unexpected plugin option
67+
.use(PluginC, null)
68+
.use(PluginC, 'foo')
69+
// @ts-expect-error type mismatch
70+
.use(PluginC, 1)

0 commit comments

Comments
 (0)