Skip to content

.get() returns object array instead of type array #29

Open

Description

@gogogoober

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

Activity

  1. JoshuaMichaelHanson commented on Mar 30, 2022

    @JoshuaMichaelHanson

    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!

  2. JoshuaMichaelHanson commented on Mar 31, 2022

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions