Browse Source

types: allow string keys in provide/inject

Evan You 6 years ago
parent
commit
1cfa2da78a
1 changed files with 3 additions and 3 deletions
  1. 3 3
      packages/runtime-core/src/apiInject.ts

+ 3 - 3
packages/runtime-core/src/apiInject.ts

@@ -3,7 +3,7 @@ import { currentInstance } from './component'
 
 
 export interface Key<T> extends Symbol {}
 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) {
   if (!currentInstance) {
     // TODO warn
     // TODO warn
   } else {
   } 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) {
   if (!currentInstance) {
     // TODO warn
     // TODO warn
   } else {
   } else {
     // TODO should also check for app-level provides
     // TODO should also check for app-level provides
     const provides = currentInstance.parent && currentInstance.provides
     const provides = currentInstance.parent && currentInstance.provides
     if (provides) {
     if (provides) {
-      const val = provides[key as any]
+      const val = provides[key as any] as any
       return isValue(val) ? val : value(val)
       return isValue(val) ? val : value(val)
     }
     }
   }
   }