provide refs is not type safe
Vue version
3.2.47
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-nyan1h?file=src/main.ts
Steps to reproduce
- Use InjectionKey with type
Ref<someObject>
- use InjectionKey to provide a
Ref<{}>
- No Type Error
import { InjectionKey, provide, ref, Ref } from 'vue';
type Cube = {
size: number;
};
const injectionKeyRef = Symbol('key') as InjectionKey<Ref<Cube>>;
// no type error
provide(injectionKeyRef, ref({}));
What is expected?
When using provide
, I expect a type error when assigning Ref<{}>
to Ref<Cube>
, the same way that {}
isn't assignable to Cube
.
What is actually happening?
Ref<{}>
is assignable to Ref<Cube>
when using provide
System Info
System:
OS: Linux 5.10 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
Memory: 3.16 GB / 7.74 GB
Container: Yes
Shell: 3.5.1 - /usr/bin/fish
Binaries:
Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
Any additional comments?
No response