2023-02-03 21:41:33 +08:00
|
|
|
import { provide, inject, InjectionKey } from 'vue'
|
|
|
|
import { expectType } from './utils'
|
2020-09-15 09:26:28 +08:00
|
|
|
|
|
|
|
const key: InjectionKey<number> = Symbol()
|
|
|
|
|
|
|
|
provide(key, 1)
|
|
|
|
// @ts-expect-error
|
|
|
|
provide(key, 'foo')
|
|
|
|
|
|
|
|
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))
|