-
Notifications
You must be signed in to change notification settings - Fork 520
Closed
Labels
status: wontfixtype: questionQuestions about the usage of the library.Questions about the usage of the library.
Description
Description
When the classToClass
or plainToClass
methods are used in conjunction with and ObjectId
instance (using the latest version of the bson module) the object id becomes a completely different one
Minimal code-snippet showcasing the problem
npm install bson class-transformer
import { ObjectId } from 'bson';
import { plainToClass } from 'class-transformer';
import assert from 'assert';
class User {
_id!: ObjectId;
}
const plainUser = { _id: new ObjectId() };
const user = plainToClass(User, plainUser);
assert(user._id.toHexString() === plainUser._id.toHexString());
Expected behavior
Assuming how this module works I expect user._id
to be a different instance than plainUser._id
but both sharing the same hexadecimal value
assert(user._id instanceof ObjectId);
assert(user._id !== plainUser._id);
assert(user._id.toHexString() === plainUser._id.toHexString());
Actual behavior
The id is converted into a completely different one
Metadata
Metadata
Assignees
Labels
status: wontfixtype: questionQuestions about the usage of the library.Questions about the usage of the library.