]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: allow string keys in provide/inject
authorEvan You <yyx990803@gmail.com>
Tue, 13 Aug 2019 15:17:55 +0000 (11:17 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 13 Aug 2019 15:17:55 +0000 (11:17 -0400)
packages/runtime-core/src/apiInject.ts

index 79121ec2fdffef78e42c6f609cf8c53d310c3042..f3133fb5a908b3376a41e0bf2b1902ada008937a 100644 (file)
@@ -3,7 +3,7 @@ import { currentInstance } from './component'
 
 export interface Key<T> extends Symbol {}
 
-export function provide<T>(key: Key<T>, value: T | Value<T>) {
+export function provide<T>(key: Key<T> | string, value: T | Value<T>) {
   if (!currentInstance) {
     // TODO warn
   } else {
@@ -22,14 +22,14 @@ export function provide<T>(key: Key<T>, value: T | Value<T>) {
   }
 }
 
-export function inject<T>(key: Key<T>): Value<T> | undefined {
+export function inject<T>(key: Key<T> | string): Value<T> | undefined {
   if (!currentInstance) {
     // TODO warn
   } else {
     // TODO should also check for app-level provides
     const provides = currentInstance.parent && currentInstance.provides
     if (provides) {
-      const val = provides[key as any]
+      const val = provides[key as any] as any
       return isValue(val) ? val : value(val)
     }
   }