Types `inject` does not support number argument
Vue version
3.3.5
Link to minimal reproduction
Steps to reproduce
See Comp.vue
file
What is expected?
Inject to not give typescript error if a number is passed
What is actually happening?
getting the error
System Info
No response
Any additional comments?
provide
seems to accept number
as key, the parameter will be converted to a string
so
provide(1, 42)
inject(1) // 42
inject('1') // 42
I think provide should not accept number
as key.
If we should type convert is acceptable. How about allow bigint, Array of number, Array of int and so on?
@xiaoxiangmoe provide already allows number
but inject does not.
How about allow bigint, Array of number, Array of int and so on?
We should only support PropertyKey
ts type.
Since this is a key for fetching data from an object, I don't think it's a good idea to get/set the same data from the key that is different types but has the same value.
inject(1) === inject('1')
So for TypeScript, I think we'd better disallow the number
type.
We have 2 solutions, either support number or drop number support from provide/inject.
For me either would be alright