diff --git a/src/foundry/client/config.d.mts b/src/foundry/client/config.d.mts index 9562a3136..3ce6f26f4 100644 --- a/src/foundry/client/config.d.mts +++ b/src/foundry/client/config.d.mts @@ -3,7 +3,6 @@ import type { ConstructorOf, PropertyTypeOrFallback } from "../../types/utils.d. import type * as CONST from "../common/constants.d.mts"; import type { StatusEffect } from "./data/documents/token.d.mts"; import type { DataModel } from "../common/abstract/module.d.mts"; -import type { SchemaField } from "../common/data/fields.d.mts"; declare global { /** diff --git a/src/foundry/common/abstract/document.d.mts b/src/foundry/common/abstract/document.d.mts index 8f007ded5..bd80a36c5 100644 --- a/src/foundry/common/abstract/document.d.mts +++ b/src/foundry/common/abstract/document.d.mts @@ -511,12 +511,21 @@ declare abstract class Document< * (default: `{}`) * @returns An array of created Document instances */ - // Excluding FogExploration because it broke polymorphism and is never embedded - createEmbeddedDocuments>( + // Excluding FogExploration because it broke polymorphism and is never embedded. Can be removed in v12 + createEmbeddedDocuments< + EmbeddedName extends Exclude, + Temporary extends boolean = false, + >( embeddedName: EmbeddedName, data?: Array>>, - context?: DocumentModificationContext, // Possibly a way to specify the parent here, but seems less relevant? - ): Promise>>>; + context?: Omit & { temporary?: Temporary }, // Possibly a way to specify the parent here, but seems less relevant? + ): Promise< + Array< + Temporary extends true + ? InstanceType> + : StoredDocument>> + > + >; /** * Update multiple embedded Document instances within a parent Document using provided differential data. @@ -528,11 +537,11 @@ declare abstract class Document< * (default: `{}`) * @returns An array of updated Document instances */ - updateEmbeddedDocuments( - embeddedName: string, + updateEmbeddedDocuments>( + embeddedName: EmbeddedName, updates?: Array>, context?: DocumentModificationContext, - ): Promise>>; + ): Promise>>>>; /** * Delete multiple embedded Document instances within a parent Document using provided string ids. @@ -543,11 +552,11 @@ declare abstract class Document< * (default: `{}`) * @returns An array of deleted Document instances */ - deleteEmbeddedDocuments( - embeddedName: string, + deleteEmbeddedDocuments>( + embeddedName: EmbeddedName, ids: Array, context?: DocumentModificationContext, - ): Promise>>; + ): Promise>>>>; /** * Get the value of a "flag" for this document diff --git a/tests/foundry/common/abstract/document.mjs.test-d.ts b/tests/foundry/common/abstract/document.mjs.test-d.ts index 462a48ab5..29e51924b 100644 --- a/tests/foundry/common/abstract/document.mjs.test-d.ts +++ b/tests/foundry/common/abstract/document.mjs.test-d.ts @@ -18,7 +18,7 @@ expectTypeOf(baseActiveEffect.toObject().changes).toEqualTypeOf(); expectTypeOf(baseActiveEffect.toObject(false).changes).toEqualTypeOf(); -const item = await Item.create({ name: "Some Item", type: "weapon" }); +const item = await Item.create({ name: "Some Item", type: "base" }); if (item) { expectTypeOf(item.toObject(false).effects[0].changes).toEqualTypeOf(); expectTypeOf(item.toObject().effects).toEqualTypeOf(); @@ -59,16 +59,16 @@ if (user) { // test creation of embedded documents declare const actor: Actor; expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: true })).toEqualTypeOf< - Promise[]> + Promise >(); expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: bool })).toEqualTypeOf< - Promise[]> + Promise[]> >(); expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: false })).toEqualTypeOf< - Promise>[]> + Promise[]> >(); expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [])).toEqualTypeOf< - Promise>[]> + Promise[]> >(); // verify that document lifecycle methods work with source data is possible