Closed WojciechKasprzyk closed 3 weeks ago
Hi @WojciechKasprzyk we're having some trouble reproducing the error message in a similar manner.
I tried getting the type for export type PostData = Awaited<ReturnType<typeof client.models.Post.list>>;
but did not get the same error. I also tried downgrading my TS version to 4.9.5 and 4.4.4 as they are mentioned in your environment info but ran into different errors like Awaited
not being available.
Can you provide a minimal sample app that reproduces the error? It seems we are both are using the latest versions of @aws-amplify/backend
and @aws-amplify/backend-cli
so it's hard to tell what the difference is.
It might also be worth checking that your @aws-amplify/data-schema
package is also up to date.
In any case, we also have type helpers that we expose on the Schema type. You should be able to use these instead.
Update: We were able to reproduce the error but it seemed finnicky. If we got the type from Schema['CmsMenu']['type']
in the same file as export type CmsMenuData = Awaited<ReturnType<typeof client.models.CmsMenu.list>>;
the error would go away. Not sure if it's an issue with VSCode or the TS server. But, are you able to use the Type helpers from Schema
instead?
Is there a particular reason why you need the return type for a list query? An alternative might be to do this instead:
export type MenuDto = Schema['CmsMenu']['type'];
type MenuListReturn = {
data: MenuDto[];
errors?: object[];
}
Hi @chrisbonifacio, Thank you for your response. The way using Schema works very well and I can get the type. I want this type to adapt DTO to the frontend data model in a separate helper file (adapter).
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
My project uses an external backend, which I fetch to retrieve a schema. I want to present the part of the schema:
Then I want to get the type of models and there are two problems:
export type PageDto = Awaited<ReturnType>;
export type PageItemsDto = PageDto['data']; export type PageItemDto = PageItemsDto['0'];
Expected behavior
I expect either:
Reproduction steps
npm install git submodule update --init --recursive npx ampx generate outputs --branch master --app-id {{backendId}}
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response