Type checks by typescript fail on Vue.set/delete
See original GitHub issueVersion
2.5.17
Reproduction link
https://github.com/nel215/vue-sandbox
Steps to reproduce
$ git clone https://github.com/nel215/vue-sandbox.git
$ cd vue-sandbox
$ yarn
$ ./node_modules/.bin/tsc index.ts
index.ts:5:9 - error TS2345: Argument of type '{}' is not assignable to parameter of type '"a"[]'.
Property 'length' is missing in type '{}'.
5 Vue.set(data.obj, 1, 'a')
~~~~~~~~
index.ts:6:12 - error TS2345: Argument of type '{}' is not assignable to parameter of type '{}[]'.
Property 'length' is missing in type '{}'.
6 Vue.delete(data.obj, 1)
What is expected?
Type checks by typescript succeed on this case.
What is actually happening?
Type checks by typescript fail on this case.
Can we use number as key of object on Vue.set/delete? If it’s yes, I will create a PR which fixes types/vue.d.ts.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Inconsistent Vue.set() and Vue.delete() TypeScript types #9353
As mentioned in #9347, there are certain cases right now where Vue types for Vue.set() and Vue.delete() work unexpectedly: Setting the value ...
Read more >Vue.js 2: Delete property from data object - Stack Overflow
The answer is: Vue.delete(users, 'foo');. It took me a while to find it, that's why I'm posting it here ;-)
Read more >strictNullChecks - TSConfig Option - TypeScript
When strictNullChecks is false , null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime.
Read more >Using Vue with TypeScript - Vue.js
With a Vite-based setup, the dev server and the bundler are transpilation-only and do not perform any type-checking. This ensures the Vite dev...
Read more >ts-loader - npm
It performs type checking in a separate process with ts-loader ... The build should fail on TypeScript compilation errors as of webpack 2....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In js, the conversion is implicit but if you want to use strict typing, then you should cast your number into a string. Doing
a[1]
or a[‘1’]` in js will implicitly access the same thing. That being said, typescript allows it without warning, so I think we should support it tooNote that the inverse is not true for arrays:
Could also go with fully strict instead, but that might annoy a few people