League-of-Foundry-Developers / foundry-vtt-types

Unofficial type declarations for the Foundry Virtual Tabletop API
MIT License
116 stars 56 forks source link

Stored Documents, when put through `toObject` or `toJson`, drop the id exists validation #2563

Open JPMeehan opened 4 months ago

JPMeehan commented 4 months ago

This test suite from tests/types/utils.test-d.ts should all work, but it doesn't because the guarantee is stripped.

declare const storedUser: StoredDocument<User>;
expectTypeOf(storedUser.id).toEqualTypeOf<string>();
expectTypeOf(storedUser._id).toEqualTypeOf<string>();
expectTypeOf(storedUser._source._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toJSON()._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toJSON()._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toObject()._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toObject()._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toObject(false)._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.toObject(false)._id).toEqualTypeOf<string>();
expectTypeOf(storedUser.clone()).toEqualTypeOf<StoredDocument<User>>();