Skip to content

Allow inferring types from Vue.set(object, ...) pattern #12504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

NikhilVerma
Copy link
Contributor

@NikhilVerma NikhilVerma commented Mar 23, 2022

Right now it's not possible to infer the type when doing Vue.set this is because Vue assumes it to be a generic object. But with a small change we can allow these types to be inferred in a clear and consistent way similar to how it's array inference works. As an added benefit it also allows autocomplete of Vue.set().

This does however disallow setting brand new properties on objects. Although setting new properties on objects/classes which aren't previously defined in Typescript can be an anti-pattern.

Playground link

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

This PR adds better type inference for Vue.set(object...) pattern, this might cause issues for existing consumers which have invalid usage of Vue.set. However I believe this is a good thing as it will allow them to fix those issues in Typescript.

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

Right now it's not possible to infer the type when doing Vue.set this is because Vue assumes it to be a generic object. But with a small change we can allow these types to be inferred in a clear and consistent way similar to how it's array inference works.
@NikhilVerma
Copy link
Contributor Author

@yyx990803 Can you please consider this? I think this offers a significant improvement in type safety of Vue.set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant