I get a type error because in my EntityHeader type, _id is required. However, when I call the create function, I want threaddb to create an _id for me and not throw a type error when I don't want to include it.
I also would prefer to leave _id typed as 'string' rather than 'string | unknown', because everywhere other than the create function will have a string value for this field.
EDIT: I had to alter the signature of create() to create(data?: Omit<T, "_id"> & { _id?: string }). I forgot to add Omit<T, "_id"> which is necessary to remove any existing _id property (potentially non-nullable) before re-adding _id?: string as a nullable field.
Description
When working with the collection.create function, I am using a type that looks like:
When I create a typed collection and try to use the collection.create function like this:
I get a type error because in my
EntityHeader
type, _id is required. However, when I call the create function, I want threaddb to create an _id for me and not throw a type error when I don't want to include it.I also would prefer to leave _id typed as 'string' rather than 'string | unknown', because everywhere other than the create function will have a string value for this field.
EDIT: I had to alter the signature of create() to
create(data?: Omit<T, "_id"> & { _id?: string })
. I forgot to add Omit<T, "_id"> which is necessary to remove any existing_id
property (potentially non-nullable) before re-adding_id?: string
as a nullable field.