Vue/TS How to add a generic T item to a reactive array of generic T items? #10534
-
I am using Vue 3.2.37 and vue-tsc 2.0.6. I am struggling to add a generic object T to a reactive array in a generic class. I believe that my issue is identical to GitHub issue #2136. I have tried to follow the advice provided, but I have failed. Can anyone please assist? The code with the VS Code complaint I am trying to resolve: The interface and object types are just guaranteeing that a few properties exist:
I have tried:
How can I add a T object to this reactive array of T objects in a way that VS Code/TypeScript will accept? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I was able to get around the TypeScript error by forcing TypeScript to read the generic array as if it were a normal array of T objects: |
Beta Was this translation helpful? Give feedback.
I was able to get around the TypeScript error by forcing TypeScript to read the generic array as if it were a normal array of T objects:
public insert() { if (!this.hasUnsavedNewRow.value) { const newItem = new (this._ctor); (this.gridItems as T[]).unshift(newItem); } }