model icon indicating copy to clipboard operation
model copied to clipboard

.get() returns object array instead of type array

Open gogogoober opened this issue 4 years ago • 2 comments

Minimal reproduction of the bug with instructions:

This bug was replicated locally and on stackblitz

StackBlitz Link

  1. Open stackblitz from demo app.
  2. When "addTodo(name: string)
  3. Check type returned form this.model.get();

type = Object[]

Expected behavior:

Type should be Todo[]

Other information:

I would be willing to submit a PR to fix this issue:

[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ x] No

gogogoober avatar Nov 03 '21 01:11 gogogoober

I am facing the same issue. For a workaround I am doing as unknown as Observable <T> In my code that uses the get() function. Would adding this same code to the model class fix the issue? If it will I can do a PR. If not please let me know what would fix the issue and I can work on it. I imported the file directly into my project so if I get it working there will push it back up for a PR. Cheers!

JoshuaMichaelHanson avatar Mar 30 '22 20:03 JoshuaMichaelHanson

Hi All,

In my testing the model does not like to work directly with TypeScript / ES classes but does function as expected when using Interface. Only real JS primitives work using Type Of, as Arrays technically are Objects. To test if and object is in-fact an array ES5 introduced the Array.isArray() function. I tested this and Array.isArray returns true with the data returned from get() so this can be closed! Cheers! https://stackoverflow.com/questions/12996871/why-does-typeof-array-with-objects-return-object-and-not-array

JoshuaMichaelHanson avatar Mar 31 '22 02:03 JoshuaMichaelHanson