Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Types: Can't use result of create in create as 'pk' is incompatible #480

@RalphSleigh

Description

@RalphSleigh

Describe the bug

With dynamodb-onetable: "2.6.2" If we try and use the return value from create to create another new item, we get a typescript error saying the pk type is incompatible:

Types of property 'pk' are incompatible.
      Type 'string | null | undefined' is not assignable to type 'string | undefined'.
        Type 'null' is not assignable to type 'string | undefined'.

To Reproduce
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgFQIYCMA2BTANHAUQDsZgYBPfAWQgBNtM4BfOAMyghDgHJbyjUIOugC0EIthgYc3AFCyAxuIDO8ZQoAW2EKjgBeRLLjG20HTABcPcZOnYLARgB0zgAzdcRkwDdsUZcDiVtyuTqEOHl7GwET0AB7YylYIUSbGYFCgqFDkyXAaqMoawWAA1h5wytCWPMrlzJ5pTI0mQvSYSYZpaQDKnNg07cmp3SZleRRg9nA9MJlEAOb43qiYAK7T3FUg2nQM3A0jo5WlE+RTVrPzS3Ar65vbu0MAJAiswAy0TAfNR6PvnzOFxmcxiNyg2AAjmtgBDaFY5htDsdmKkWIU4EoiKoWulsoJOikUcAqgARVAwRIIqAbXHdUg7VSCMCdRF4NGeJjySbYGb9QYMZDnXkGYikCgAHh5EFYlU02lQTjaDGUTj6OwFmAAfPIsao4FIsCK4BIAO4oOwACgQTAAlLqVPB1QM9phNVZNRLnZqhVMtfoDXYnAtJJrLQAib2u8P2xSOk3YU1R9oB1Cm1BkPka12apwKCEU7DWgGYeHhgDypXDdvkZuTDCcJdoAfDADkIPBK+GHdj4KgiB2tFBW4n64wDGPc-nsIXLXX+a7bUA

import { Table, Entity, Model } from 'dynamodb-onetable'

const schema = {
    format: 'onetable:1.1.0',
    version: '0.0.1',
    indexes: {
        primary: { hash: 'pk', sort: 'sk' },
    },
    models: {
        SomeModel: {
            pk: { type: String, value: 'somemodel' },
            sk: { type: String, value: 'somemodel:${field}' },
            field: { type: String, required: true },
        }
    } as const,
    params: {
        isoDates: true,
        timestamps: true,
    },
}

type SomeModelType = Entity<typeof schema.models.SomeModel>

const table = new Table({})

const SomeModelModel: Model<SomeModelType> = table.getModel("SomeModel")

const newSomeModel = await SomeModelModel.create({field:"Ok"})

newSomeModel.field = "Not Ok"

const anotherNewSomeModel = await SomeModelModel.create(newSomeModel)

Error is on the last line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions