Closed crafael23 closed 4 months ago
Schema types should be accessed like this:
const [todos, setTodos] = useState<Schema["Todo"]["type"][]>([]);
Schema types should be accessed like this:
const [todos, setTodos] = useState<Schema["Todo"]["type"][]>([]);
That makes sense, how come the "example" shown from the other repository does not require it?
Schema types should be accessed like this:
const [todos, setTodos] = useState<Schema["Todo"]["type"][]>([]);
That makes sense, how come the "example" shown from the other repository does not require it?
The example is a bit old, the type syntax has changed since then.
Hi @crafael23 thanks for raising this issue. @kekami is right, the syntax in the repo is outdated.
The Schema["Todo"]["type"]
is the correct way to access the types for models.
I raised a PR to update the repo.
I'll close this issue as it is expected behavior on the latest package versions.
Hi @crafael23 thanks for raising this issue. @kekami is right, the syntax in the repo is outdated.
The
Schema["Todo"]["type"]
is the correct way to access the types for models.I raised a PR to update the repo.
I'll close this issue as it is expected behavior on the latest package versions.
Hi, thank you for clarifying, u too @kekami. That pretty much did it.
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Not applicable
Amplify Version
v6
Amplify Categories
api
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
Im trying to type a variable based on the schema described on the amplify backend files and it is adding a Key named Type that prevents me from properly utilizing the type system correctly
As seen in the image above that
type:
field shouldnt be there and it is causing the following error when trying to assign an object which was queried directly from the backend properly and should be that exact same object.This prevents me from typing other variables correctly for me to for example pass the object as a prop towards a function or component.
The Schema type is being declared exactly as the documentation instructs.
Expected behavior
The expected behavior, would be , as the example proyect done by ErickCH in this repository, that when invoking
Schema["AnyField"]
for it to return only the types for the schema without thattype
key field which disrupts everythingIn this image we can see that the type for Post is being properly assigned to the parameter
This is that proyect's package.json dependencies.
"dependencies": { "@aws-amplify/adapter-nextjs": "^1.0.8", "@aws-amplify/ui-react": "^6.0.7", "aws-amplify": "^6.0.8", "next": "14.0.4", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@aws-amplify/backend": "^0.6.0", "@aws-amplify/backend-cli": "^0.9.2", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "autoprefixer": "^10.0.1", "eslint": "^8", "eslint-config-next": "14.0.4", "postcss": "^8", "tailwindcss": "^3.3.0", "typescript": "^5.3.3"
Reproduction steps
Go to any other file or component and try to use that schema for a specific table as a type
Code Snippet
No response
Log output
No response
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
package.json
tsconfig.json