amplify-js: type errors when using client.models.mymodel.create

Before opening, please confirm:

JavaScript Framework

Vue

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

function

Backend

Amplify Gen 2 (Preview)

Environment information

Screenshot 2024-08-08 at 07 35 25 Screenshot 2024-08-08 at 07 35 56

Type script errors are being generated incorrectly when using the create method from a model generated with amplify v2


</details>


### Describe the bug


### Expected behavior

See screenshot. I expect the typescript errors to not be there!


### Reproduction steps

create a simple model through amplify v2. Use typescript. Addec code for example.

### Code Snippet

```javascript
  Run: a
    .model({
      prompt: a.belongsTo('Prompt', 'promptId'),
      promptId: a.id(),
      trigger: a.string(),
      promptContent: a.string(),
      promptName: a.string(),
      promptCron: a.string(),
      runLabel: a.string(),
      startTimestamp: a.timestamp(),
      endTimestamp: a.timestamp(),
      isRunning: a.boolean(),
      accessToken: a.string(),
      messages: a.hasMany('Message', 'runId')
    })



  const createCommand = await client.models.Run.create({
    trigger: 'manual',
    promptId: selectedPrompt.value.id,
    promptName: selectedPrompt.value.name,
    promptContent: selectedPrompt.value.content,
    promptCron: selectedPrompt.value.cron,
    runLabel: runLabel,
    isRunning: false,
    startTimestamp: startEpoc,
    accessToken: session.tokens.accessToken.toString(),
    endTimestamp: null
  })

Log output

// Put your logs below this line


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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

It looks like the project where Amplify is installed must have strict set to true in its tsconfig.json file. After adding that my compile errors went away.

{
  "compilerOptions": {
    "strict": true,
    ...
  },
  ...
}