inject-test.ts 509 B

12345678910111213141516
  1. import { InjectionKey, provide, inject } from '../../index'
  2. import { expectType } from '../utils'
  3. const key: InjectionKey<number> = Symbol()
  4. provide(key, 1)
  5. // @ts-expect-error
  6. provide(key, 'foo')
  7. expectType<number | undefined>(inject(key))
  8. expectType<number>(inject(key, 1))
  9. expectType<number>(inject(key, () => 1, true /* treatDefaultAsFactory */))
  10. expectType<() => number>(inject('foo', () => 1))
  11. expectType<() => number>(inject('foo', () => 1, false))
  12. expectType<number>(inject('foo', () => 1, true))