From 7691c0652075e7f43ae49b25a051210a3b947f87 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 20 Aug 2019 15:51:55 -0400 Subject: [PATCH] wip: warn when injection not found --- packages/runtime-core/src/apiInject.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 93d5e39a..b9e105fe 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -1,4 +1,5 @@ import { currentInstance } from './component' +import { warn } from './warning' export interface InjectionKey extends Symbol {} @@ -29,8 +30,12 @@ export function inject(key: InjectionKey | string, defaultValue?: any) { } else { // TODO should also check for app-level provides const provides = currentInstance.parent && currentInstance.provides - return provides && key in provides - ? (provides[key as any] as any) - : defaultValue + if (provides && key in provides) { + return provides[key as any] as any + } else if (defaultValue !== undefined) { + return defaultValue + } else if (__DEV__) { + warn(`injection ${key} not found.`) + } } }