-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
7.3.0
Node.js version
18.16.0
MongoDB server version
5.x
Typescript version (if applicable)
5.1.3
Description
Directly assigning to fields of a document fails with v7 when the document is generic (special case, see example).
Steps to Reproduce
import { Model } from 'mongoose';
interface ResourceDoc {
foo: string;
}
type ResourceIdT<ResourceIdField extends string> = {
[key in ResourceIdField]: string;
}
type ResourceDocWithId<ResourceIdField extends string> = ResourceDoc & ResourceIdT<ResourceIdField>;
class TestClass<
ResourceType extends string,
DocT extends ResourceDocWithId<`${ResourceType}Id`>>
{
constructor(dbModel: Model<DocT>) {
const resourceDoc = new dbModel();
resourceDoc.foo = 'bar'; // Type 'string' is not assignable to type 'Require_id<DocT>["foo"]'
}
}
If I replace `${ResourceType}Id`
with 'FooId'
then it works.
Expected Behavior
It should work.
Metadata
Metadata
Assignees
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request