Repository: vuejs/composition-api (ts)

Issue:
warning should be triggered when the injectionKey is undefined
Version: 1.0.0-rc.14

The reproduced demo is: https://codesandbox.io/s/angry-hodgkin-crnyd

The main code is as follows:

```vue
<script>
import { inject } from "@vue/composition-api";
export default {
  name: "HelloWorld",
  setup() {
    const emptyKey = inject();
    console.log(emptyKey); // should warn unfound
    return {
      msg,
    };
  },
};
</script>

```

Pull request description:
fix(runtime-core):  trigger warning when the injectionKey is undefined
fix #761 

Patch:
diff --git a/src/apis/inject.ts b/src/apis/inject.ts
index 4418379..75b5301 100644
--- a/src/apis/inject.ts
+++ b/src/apis/inject.ts
@@ -48,10 +48,6 @@ export function inject(
   defaultValue?: unknown,
   treatDefaultAsFactory = false
 ) {
-  if (!key) {
-    return defaultValue
-  }
-
   const vm = getCurrentInstance()?.proxy
   if (!vm) {
     __DEV__ &&
@@ -59,6 +55,11 @@ export function inject(
     return
   }
 
+  if (!key) {
+    __DEV__ && warn(`injection "${String(key)}" not found.`, vm)
+    return defaultValue
+  }
+
   const val = resolveInject(key, vm)
   if (val !== NOT_FOUND) {
     return val


Test patch:
diff --git a/test/v3/runtime-core/apiInject.spec.ts b/test/v3/runtime-core/apiInject.spec.ts
index f4593ea..1ed7d5c 100644
--- a/test/v3/runtime-core/apiInject.spec.ts
+++ b/test/v3/runtime-core/apiInject.spec.ts
@@ -242,6 +242,28 @@ describe('api: provide/inject', () => {
     expect(`[Vue warn]: Injection "foo" not found`).toHaveBeenWarned()
   })
 
+  it('should warn unfound w/ injectionKey is undefined', () => {
+    const Provider = {
+      setup() {
+        return () => h(Consumer)
+      },
+    }
+
+    const Consumer = {
+      setup() {
+        // The emulation does not use TypeScript
+        const foo = inject(undefined as unknown as string)
+        expect(foo).toBeUndefined()
+        return () => h('div', foo as unknown as string)
+      },
+    }
+
+    const root = document.createElement('div')
+    const vm = createApp(Provider).mount(root)
+    expect(vm.$el.outerHTML).toBe(`<div></div>`)
+    expect(`[Vue warn]: injection "undefined" not found.`).toHaveBeenWarned()
+  })
+
   it('should not self-inject', () => {
     const Comp = {
       setup() {