Skip to content

Commit

Permalink
Fix all other compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeAbby committed Oct 19, 2024
1 parent cf3a3bb commit cfe164d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
35 changes: 19 additions & 16 deletions src/foundry/client/apps/forms/effect-config.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GetDataReturnType, MaybePromise, ValueOf } from "../../../../types/utils.d.mts";
import type { GetDataReturnType, MaybePromise, SimpleMerge, ValueOf } from "../../../../types/utils.d.mts";

declare global {
/**
Expand Down Expand Up @@ -52,23 +52,26 @@ declare global {
namespace ActiveEffectConfig {
type Any = ActiveEffectConfig<any>;

interface ActiveEffectConfigData<
type ActiveEffectConfigData<
Options extends
DocumentSheetOptions<ActiveEffect.ConfiguredInstance> = DocumentSheetOptions<ActiveEffect.ConfiguredInstance>,
> extends DocumentSheet.DocumentSheetData<Options, ActiveEffect.ConfiguredInstance> {
labels: {
transfer: {
name: string;
hint: string;
> = SimpleMerge<
DocumentSheet.DocumentSheetData<Options, ActiveEffect.ConfiguredInstance>,
{
labels: {
transfer: {
name: string;
hint: string;
};
};
};
effect: ActiveEffectConfig["object"]; // Backwards compatibility
data: ActiveEffectConfig["object"];
isActorEffect: boolean;
isItemEffect: boolean;
submitText: string;
modes: Record<ValueOf<typeof CONST.ACTIVE_EFFECT_MODES>, string>;
descriptionHTML: string;
}
effect: ActiveEffectConfig["object"]; // Backwards compatibility
data: ActiveEffectConfig["object"];
isActorEffect: boolean;
isItemEffect: boolean;
submitText: string;
modes: Record<ValueOf<typeof CONST.ACTIVE_EFFECT_MODES>, string>;
descriptionHTML: string;
}
>;
}
}
4 changes: 2 additions & 2 deletions src/foundry/client/data/documents/token.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ declare global {

override getEmbeddedCollection<DocType extends Document.Type>(
embeddedName: DocType,
): Collection<InstanceType<Document.ConfiguredClassForName<DocType>>>;
): Collection<Document.ConfiguredInstanceForName<DocType>>;

protected override _preUpdate(
data: foundry.documents.BaseToken.UpdateData,
options: DocumentModificationOptions,
user: User.ConfiguredInstance,
user: foundry.documents.BaseUser,
): Promise<void>;

protected override _onUpdate(
Expand Down
2 changes: 1 addition & 1 deletion src/foundry/client/pixi/placeables/wall.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ declare global {

override activateListeners(): void;

protected override _canControl(user: User, event?: any): boolean;
protected override _canControl(user: User.ConfiguredInstance, event?: any): boolean;

protected override _onHoverIn(event: PIXI.FederatedEvent, options?: PlaceableObject.HoverInOptions): false | void;

Expand Down
33 changes: 29 additions & 4 deletions src/foundry/common/abstract/document.d.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { ConfiguredDocuments } from "../../../types/configuredDocuments.d.mts";
import type { GetKey, MakeConform } from "../../../types/helperTypes.mts";
import type { DeepPartial, EmptyObject, InexactPartial, RemoveIndexSignatures } from "../../../types/utils.mts";
import type {
AnyObject,
DeepPartial,
EmptyObject,
InexactPartial,
RemoveIndexSignatures,
} from "../../../types/utils.mts";
import type * as CONST from "../constants.mts";
import type { DataField } from "../data/fields.d.mts";
import type { fields } from "../data/module.mts";
Expand Down Expand Up @@ -479,9 +485,9 @@ declare abstract class Document<
* @returns The Collection instance of embedded Documents of the requested type
* @remarks Usually returns some form of DocumentCollection, but not always (e.g. Token["actors"])
*/
getEmbeddedCollection<DocType extends Document.TypeName>(
getEmbeddedCollection<DocType extends Document.Type>(
embeddedName: DocType,
): Collection<InstanceType<Document.ConfiguredClassForName<DocType>>>;
): Collection<Document.ConfiguredInstanceForName<DocType>>;

/**
* Get an embedded document by its id from a named collection in the parent document.
Expand Down Expand Up @@ -524,7 +530,7 @@ declare abstract class Document<
Temporary extends boolean = false,
>(
embeddedName: EmbeddedName,
data?: Array<Document.ConstructorDataFor<Document.ConfiguredClassForName<EmbeddedName>>>,
data?: Array<AnyObject>,
context?: Omit<Document.ModificationContext<this["parent"]>, "temporary"> & { temporary?: Temporary }, // Possibly a way to specify the parent here, but seems less relevant?
): Promise<
Array<
Expand Down Expand Up @@ -840,6 +846,25 @@ declare namespace Document {
// TODO: Probably a way to auto-determine this
type SystemType = "Actor" | "Card" | "Cards" | "Item" | "JournalEntryPage";

type EmbeddableNamesFor<ConcreteDocument extends Document.Internal.Instance.Any> = {
[K in keyof ConfiguredDocuments]: IsParentOf<ConcreteDocument, InstanceType<ConfiguredDocuments[K]>> extends true
? K
: never;
};

type ParentOf<ConcreteDocument extends Document.Internal.Instance.Any> =
ConcreteDocument extends Document.Internal.Instance<any, any, infer Parent> ? Parent : never;

type NameOf<ConcreteDocument extends Document.Internal.Instance.Any> =
ConcreteDocument extends Document.Internal.Instance<any, infer ConcreteMetadata, any>
? ConcreteMetadata["name"]
: never;

type IsParentOf<
ParentDocument extends Document.Internal.Instance.Any,
ChildDocument extends Document.Internal.Instance.Any,
> = NameOf<ParentDocument> extends NameOf<ParentOf<ChildDocument>> ? true : false;

// Documented at https://gist.github.com/LukeAbby/c7420b053d881db4a4d4496b95995c98
namespace Internal {
type Constructor = (abstract new (arg0: never, ...args: never[]) => Instance.Any) & {
Expand Down
2 changes: 1 addition & 1 deletion src/foundry/common/data/fields.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ declare namespace StringField {
* @typeParam Options - the options that override the default options
*/
type InitializedType<Options extends StringFieldOptions> = DataField.DerivedInitializedType<
ValidChoice<Options>,
ValidChoice<Options> & (string | null | undefined),
MergedOptions<Options>
>;

Expand Down
3 changes: 2 additions & 1 deletion src/foundry/common/packages/base-package.d.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { GetKey } from "../../../types/helperTypes.d.mts";
import type { AnyObject, InexactPartial } from "../../../types/utils.d.mts";
// eslint-disable-next-line import/no-named-as-default
import type DataModel from "../abstract/data.d.mts";
Expand Down Expand Up @@ -544,7 +545,7 @@ declare class BasePackage<
* @deprecated since v10, will be removed in v13
* @remarks `"You are accessing BasePackage#name which is now deprecated in favor of id."`
*/
get name(): this["id"];
get name(): GetKey<this, "id">;

/**
* A flag which defines whether this package is unavailable to be used.
Expand Down
5 changes: 1 addition & 4 deletions src/foundry/common/types.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ declare global {
}

// This type is named `SettingConfig` in FoundryVTT but that name is confusing within fvtt-types because of the `Config` nomenclature meaning declaration merging.
interface _SettingOptions<
RuntimeType extends ClientSettings.RuntimeType,
AssignmentType extends ClientSettings.TypeScriptType,
> {
interface _SettingOptions<RuntimeType extends ClientSettings.RuntimeType, AssignmentType> {
/** A unique machine-readable id for the setting */
key: string;

Expand Down

0 comments on commit cfe164d

Please sign in to comment.