Skip to content
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

Cant find meta on PromiseManyArray #1539

Open
1 task done
Techn1x opened this issue Nov 11, 2022 · 5 comments
Open
1 task done

Cant find meta on PromiseManyArray #1539

Techn1x opened this issue Nov 11, 2022 · 5 comments
Labels
types:core:data Something is wrong with the Ember Data type definitions types:core Something is wrong with the Ember type definitions

Comments

@Techn1x
Copy link

Techn1x commented Nov 11, 2022

Which package(s) does this problem pertain to?

  • @types/ember

Maybe others?

What are instructions we can follow to reproduce the issue?

  1. Update to @types/ember 4.0.2 EDIT: This error appeared for me when I updated types/ember to 4.0.2, but the sandbox link below shows the issue and it's on types/ember 3.x, so not sure what's going on
  2. Perform a query, try to access meta key, typescript will say it doesn't exist
const booksResult = await this.store.query('book-library/book', bookSearchQuery)
console.log(booksResult.meta) // Property 'meta' does not exist on type 'ArrayProxy<BookLibraryBook>'
Reproduction Case

I've done my best to create a sandbox here.
https://codesandbox.io/s/my-app-forked-4v11p8?file=/app/routes/index.ts

The sandbox IDE does not show redline errors, but if you open a terminal and type yarn tsc --build you'll see the error

Screenshot from 2022-11-11 13-31-57

Now about that bug. What did you expect to see?

meta property should exist on ArrayProxy and not cause a TS error

What happened instead?

Typescript says meta property does not exist

Screenshot from 2022-11-11 13-03-43
Screenshot from 2022-11-11 13-03-55

Thought I would try a different key update() that was mentioned in an issue that I think might be related?
#1525
Screenshot from 2022-11-11 13-04-22

@Techn1x Techn1x changed the title Cant find meta on ArrayProxy in @types/ember 4.0.2 Cant find meta on ArrayProxy Nov 11, 2022
@sleroq
Copy link

sleroq commented Jun 16, 2023

Meta property does exist in my case, but I can't figure out how to specify type for it, without casting after query.

@chriskrycho
Copy link
Member

Sorry for the long delay in responding! This is a gap/error in the definition of the ArrayProxy type on DefinitelyTyped, though ArrayProxy itself may not be the source of the issue. The Ember Data and Ember TypeScript teams are working on a plan to publish much-corrected types from the Ember Data packages directly, following the same overall approach as ember-source followed; in the meantime, you may be able to fix this by submitting a PR to DefinitelyTyped to correct the type, and Ember Data maintainers have the ability to review that.

@chriskrycho chriskrycho added the types:core Something is wrong with the Ember type definitions label Sep 28, 2023
@chriskrycho
Copy link
Member

Ah, a further and more important update: the types for ArrayProxy itself are now guaranteed to be correct, because they’re published from Ember’s own source code. As such, if the field is public, it is in the types! The reason I referred to Ember Data types above is because the .meta field is for a ManyArray or PromiseManyArray, not for ArrayProxy itself. I'm going to update the issue description accordingly so others are not confused in the future.

@chriskrycho chriskrycho changed the title Cant find meta on ArrayProxy Cant find meta on PromiseManyArray Sep 28, 2023
@chriskrycho chriskrycho added the types:core:data Something is wrong with the Ember Data type definitions label Sep 29, 2023
@Techn1x
Copy link
Author

Techn1x commented Sep 29, 2023

Thanks for the response Chris (I just watched some of your Glint videos with Dan Freeman very informative thankyou!)

It has been some time since I opened this issue and with various updates it has changed somewhat. It seems that the record type is now AdapterPopulatedRecordArray<> which also doesn't seem to contain a meta key?

const booksResult = await this.store.query('book-library/book', bookSearchQuery)
const { groups = [] }: { groups: BookSearchResultsGroup[] } = booksResult.meta

Is there somewhere that I am supposed to add a type for the meta property here?

I am running Ember 4.12.3 and ember-data 4.12.3. If this issue goes away in Ember 5 or ember-data 5 let me know and I'm happy to continue ignoring it until we upgrade

This is in a service.ts file
Screenshot 2023-09-29 at 12 23 32 pm

@GerritSommer
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types:core:data Something is wrong with the Ember Data type definitions types:core Something is wrong with the Ember type definitions
Projects
None yet
Development

No branches or pull requests

4 participants