Computed generic type stripping ruin the type strictness
dvh91 opened this issue · comments
Vue version
3.4.21
Link to minimal reproduction
Steps to reproduce
- create a object type
- pass it into the computed generics
- add additional property
What is expected?
computed generic type should behave just as the ref and to properly respect the type strictness
What is actually happening?
computed generic type does not work as expected
System Info
System:
OS: macOS 13.5.2
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 29.86 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
bun: 1.0.26 - ~/.bun/bin/bun
Browsers:
Chrome: 123.0.6312.105
Safari: 16.6
npmPackages:
vue: ^3.4.21 => 3.4.21
Any additional comments?
No response
This is a TS limitation - it allows for additional properties in certain situations.
TS types don't strictly enforce that only the defined properties are present on objects. It only enforces that required properties are present and that the types of defined properties do match. The fact that it does reject additional properties for objects defined inline (and only inline!) in function calls is kinda an exception to that rule.
This is also part of the reason why in Object.keys(obj, (key) => )
the key
argument is typed as string
, and not keyof obj
- TS can't completely guarantee that there are only the keys defined by obj
.
Here's an example using a plain function, which has the same problem.