From: Evan You Date: Tue, 13 Aug 2019 15:17:55 +0000 (-0400) Subject: types: allow string keys in provide/inject X-Git-Tag: v3.0.0-alpha.0~930 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1cfa2da78a3933eb22d14fe77f1e2674ce9dacbf;p=thirdparty%2Fvuejs%2Fcore.git types: allow string keys in provide/inject --- diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 79121ec2fd..f3133fb5a9 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -3,7 +3,7 @@ import { currentInstance } from './component' export interface Key extends Symbol {} -export function provide(key: Key, value: T | Value) { +export function provide(key: Key | string, value: T | Value) { if (!currentInstance) { // TODO warn } else { @@ -22,14 +22,14 @@ export function provide(key: Key, value: T | Value) { } } -export function inject(key: Key): Value | undefined { +export function inject(key: Key | string): Value | 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) } }