Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Model.create allows creating Partial objects that do not match the type #1677

Open
6 tasks done
AKK9 opened this issue May 1, 2024 · 0 comments
Open
6 tasks done

Comments

@AKK9
Copy link

AKK9 commented May 1, 2024

Summary:

I believe the parameter type for Model.create() is incorrect. It is currently Partial<T>, but I believe it would be more appropriate to use T instead to warn users when required fields are missing from a new item.

For example, you can create an item using Model.create() where you pass in a Partial<T>, then when you fetch that item using Model.get() it will return a Promise<T>. Now your types won't match your object.

Code sample:

Schema

// Strongly typed model
class Cat extends Item {
    id: number;
    name: string;
}

Model

const CatModel = dynamoose.model<Cat>("Cat", {"id": Number, "name": String});

General

CatModel.create({ "id": 1 });

Current output and behavior (including stack trace):

Using the example from the docs, that create call won't cause any type errors.

Expected output and behavior:

I believe this should cause a type error, because the Cat class contains a name field which is not optional and create shouldn't allow you to pass in an invalid object.

Environment:

Operating System: MacOS
Operating System Version: Sonama 14.4.1
Node.js version (node -v): 20.12.1
NPM version: (npm -v): yarn 1.22.22
Dynamoose version: 4.0.1

Other information (if applicable):

No other information.

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant