vuejs / core

đź–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Home Page:https://vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Computed generic type stripping ruin the type strictness

dvh91 opened this issue · comments

Vue version

3.4.21

Link to minimal reproduction

https://play.vuejs.org/#eNqFkkFPwkAQhf/KZC/FhOBBTxUwohz0oEY87qW001Jodze7U4SQ/ndntwFqNHhr37z3+u10D+LBmNG2QRGLsUttaQgcUmOgSlQxkYKcFFOpytpoS3AAi/kQUl2bhjCDFnKra4i4ILqTSiraG4QZLsiWKcEEDlIB5FrH4FhSBZsAlom9j0E19RItC21Iplo5gkyjm9clza3VNv7V5BQmm30M0Qr30ZCj5ySDPfXDHGFpfGyYDs4okY/2yuJBxFVXPykU9auOJ+71Da5gMoX/a7l3fN2tlhfJL4S1qRJCfgNYYVVp7+ipYshrZ5K8LEZrpxX/m/AVKTxGWaF9M1QyqRRxtxc/S7jo6yVoZBsMLCGzwnTzh752O69J8W7Rod2iFKcZJbZA6sbzxSvu+Pk0rHXWVOy+MPxAp6vGM3a2WaMyxu75Au1zuFV8LT7dfEeo3PFQHtQ72+CXgu/X44Wjn3FvRrchx4sX7TdaEPTz

Steps to reproduce

  1. create a object type
  2. pass it into the computed generics
  3. 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.

https://play.vuejs.org/#eNqNU01v2zAM/SuELk6BIDlsJy/JsG4ZsB3Woc1hA3xRbCZWYkuCRDUJgvz3Uk79UbQoCl8sku/pPZI6i2/WTh4DilTMfO6UJfBIwUIl9XaeCfKZWGRa1dY4gjM43IwhN7UNhAVcYONMDQkTJF8ynWk6WYRbfCCncoI5nDMNsDEmBc8hveUigLV0X1PQoV6j48ClQeZGe4LCoF/WipbOGZe+YvIa5f6UQlLiKRkztEeysB9DMEM4NGsZFqNeShKhA7J0lDDVTaf/Z9D5Cj3NVgtmGd3AfAGrmJ1O4b8JkEvN3BScBlkUipTRsgLrjEVHCj0oDVRiWxM5x3AoVV6C8rBXupB8lNT3MdoG6eGAVTVpHf1LeyWdjU7Qx/z0XdU0bE1786A/H6Ud8B6c0du79e7FoN+GPbePSu6Ald73fl+Q3ePm1eDaW5qL4zebXjeV95IPhLWtJCGfAEomNLFiEBVj3mK+Y6O2k503mle9UZuJ2AVVobuzcYa86enVR8xJJjr8bmLkAjaeGkyJ+f6N+M4fYywTfx16dI+YiS5H0m2Rrunlwx888n+XrE0RKq5+J3mP3lQharyW3QZdsOxBXaP2V/NI+ZWt/PJIqH1rKgqNlZemPhP8XL+/Y72X+2nyucHxAMXlCRLpZtg=