ember-cli-typescript
ember-cli-typescript copied to clipboard
Cant find `meta` on `PromiseManyArray`
Which package(s) does this problem pertain to?
- [x] @types/ember
Maybe others?
What are instructions we can follow to reproduce the issue?
- ~Update to
@types/ember4.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 - Perform a query, try to access
metakey, 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

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

Thought I would try a different key update() that was mentioned in an issue that I think might be related?
https://github.com/typed-ember/ember-cli-typescript/issues/1525

Meta property does exist in my case, but I can't figure out how to specify type for it, without casting after query.
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.
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.
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