forked from vuejs/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinject.test-d.ts
More file actions
54 lines (43 loc) · 1.15 KB
/
inject.test-d.ts
File metadata and controls
54 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
type InjectionKey,
type Ref,
createApp,
inject,
provide,
ref,
} from 'vue'
import { expectType } from './utils'
// non-symbol keys
provide('foo', 123)
provide(123, 123)
const key = Symbol() as InjectionKey<number>
provide(key, 1)
// @ts-expect-error
provide(key, 'foo')
// @ts-expect-error
provide(key, null)
expectType<number | undefined>(inject(key))
expectType<number>(inject(key, 1))
expectType<number>(inject(key, () => 1, true /* treatDefaultAsFactory */))
expectType<() => number>(inject('foo', () => 1))
expectType<() => number>(inject('foo', () => 1, false))
expectType<number>(inject('foo', () => 1, true))
// #8201
type Cube = {
size: number
}
const injectionKeyRef = Symbol('key') as InjectionKey<Ref<Cube>>
// @ts-expect-error
provide(injectionKeyRef, ref({}))
// naive-ui: explicit provide type parameter
provide<Cube>('cube', { size: 123 })
provide<Cube>(123, { size: 123 })
provide<Cube>(injectionKeyRef, { size: 123 })
// @ts-expect-error
provide<Cube>('cube', { size: 'foo' })
// @ts-expect-error
provide<Cube>(123, { size: 'foo' })
// #10602
const app = createApp({})
// @ts-expect-error
app.provide(injectionKeyRef, ref({}))