@league-of-foundry-developers/foundry-vtt-types 13.346.0-beta.20250709012529 → 13.346.0-beta.20250709090128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@league-of-foundry-developers/foundry-vtt-types",
4
- "version": "13.346.0-beta.20250709012529",
4
+ "version": "13.346.0-beta.20250709090128",
5
5
  "description": "TypeScript type definitions for Foundry VTT",
6
6
  "type": "module",
7
7
  "types": "./src/index.d.mts",
@@ -348,3 +348,41 @@ export interface SettingConfig {
348
348
  */
349
349
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
350
350
  export interface SystemNameConfig {}
351
+
352
+ /**
353
+ * Controls various behaviors of `system`. By default fvtt-types forces you to account for all
354
+ * possible subtypes of a document. This helps make your code more robust for things like the
355
+ * arbitrary module subtypes that may exist. This is why if you try writing `item.system.someProp`
356
+ * you are going to get an error like:
357
+ * ```text
358
+ * Property 'someProp' does not exist on type 'SystemOfType<...>'.
359
+ * Property 'someProp' does not exist on type 'UnknownTypeDataModel'.
360
+ * ```
361
+ *
362
+ * While inconvenient this is necessary for soundness. As a module subtype is designed to be
363
+ * completely arbitrary they could have a conflicting property with any shape. Therefore it's
364
+ * recommended to work around this with helpers that make it easier to actually account for module
365
+ * subtypes like an `isKnown` helper etc. but if you want to tweak the behavior for certain classes
366
+ * you can add `discriminate: "all"` which will make `item.system.someProp` be typed as
367
+ * `T | undefined`.
368
+ *
369
+ * Even more unsoundly, you can entirely ignore the existence of module subtypes and `"base"`
370
+ * entirely with `moduleSubtype: "ignore"` and `base: "ignore"`.
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * declare module "fvtt-types/configuration" {
375
+ * interface SystemConfig {
376
+ * Item: {
377
+ * discriminate: "all";
378
+ * };
379
+ * Actor: {
380
+ * moduleSubtype: "ignore";
381
+ * base: "ignore";
382
+ * };
383
+ * }
384
+ * }
385
+ * ```
386
+ */
387
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
388
+ export interface SystemConfig {}
@@ -101,7 +101,7 @@ declare namespace ActiveEffect {
101
101
  * builtin `ActiveEffect` class or a custom subclass if that is set up in
102
102
  * {@link ConfiguredActiveEffect | `fvtt-types/configuration/ConfiguredActiveEffect`}.
103
103
  */
104
- type OfType<Type extends SubType> = _OfType[Type];
104
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
105
105
 
106
106
  /** @internal */
107
107
  interface _OfType
@@ -117,7 +117,7 @@ declare namespace ActiveEffect {
117
117
  /**
118
118
  * `SystemOfType` returns the system property for a specific `ActiveEffect` subtype.
119
119
  */
120
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
120
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
121
121
 
122
122
  /**
123
123
  * @internal
@@ -98,7 +98,7 @@ declare namespace ActorDelta {
98
98
  * builtin `ActorDelta` class or a custom subclass if that is set up in
99
99
  * {@link ConfiguredActorDelta | `fvtt-types/configuration/ConfiguredActorDelta`}.
100
100
  */
101
- type OfType<Type extends SubType> = _OfType[Type];
101
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
102
102
 
103
103
  /** @internal */
104
104
  interface _OfType
@@ -114,7 +114,7 @@ declare namespace ActorDelta {
114
114
  /**
115
115
  * `SystemOfType` returns the system property for a specific `ActorDelta` subtype.
116
116
  */
117
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
117
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
118
118
 
119
119
  /**
120
120
  * @internal
@@ -109,7 +109,7 @@ declare namespace Actor {
109
109
  * builtin `Actor` class or a custom subclass if that is set up in
110
110
  * {@link ConfiguredActor | `fvtt-types/configuration/ConfiguredActor`}.
111
111
  */
112
- type OfType<Type extends SubType> = _OfType[Type];
112
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
113
113
 
114
114
  /** @internal */
115
115
  interface _OfType
@@ -125,7 +125,7 @@ declare namespace Actor {
125
125
  /**
126
126
  * `SystemOfType` returns the system property for a specific `Actor` subtype.
127
127
  */
128
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
128
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
129
129
 
130
130
  /**
131
131
  * @internal
@@ -99,7 +99,7 @@ declare namespace Card {
99
99
  * builtin `Card` class or a custom subclass if that is set up in
100
100
  * {@link ConfiguredCard | `fvtt-types/configuration/ConfiguredCard`}.
101
101
  */
102
- type OfType<Type extends SubType> = _OfType[Type];
102
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
103
103
 
104
104
  /** @internal */
105
105
  interface _OfType
@@ -115,7 +115,7 @@ declare namespace Card {
115
115
  /**
116
116
  * `SystemOfType` returns the system property for a specific `Card` subtype.
117
117
  */
118
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
118
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
119
119
 
120
120
  /**
121
121
  * @internal
@@ -104,7 +104,7 @@ declare namespace Cards {
104
104
  * builtin `Cards` class or a custom subclass if that is set up in
105
105
  * {@link ConfiguredCards | `fvtt-types/configuration/ConfiguredCards`}.
106
106
  */
107
- type OfType<Type extends SubType> = _OfType[Type];
107
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
108
108
 
109
109
  /** @internal */
110
110
  interface _OfType
@@ -120,7 +120,7 @@ declare namespace Cards {
120
120
  /**
121
121
  * `SystemOfType` returns the system property for a specific `Cards` subtype.
122
122
  */
123
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
123
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
124
124
 
125
125
  /**
126
126
  * @internal
@@ -98,7 +98,7 @@ declare namespace ChatMessage {
98
98
  * builtin `ChatMessage` class or a custom subclass if that is set up in
99
99
  * {@link ConfiguredChatMessage | `fvtt-types/configuration/ConfiguredChatMessage`}.
100
100
  */
101
- type OfType<Type extends SubType> = _OfType[Type];
101
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
102
102
 
103
103
  /** @internal */
104
104
  interface _OfType
@@ -114,7 +114,7 @@ declare namespace ChatMessage {
114
114
  /**
115
115
  * `SystemOfType` returns the system property for a specific `ChatMessage` subtype.
116
116
  */
117
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
117
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
118
118
 
119
119
  /**
120
120
  * @internal
@@ -105,7 +105,7 @@ declare namespace Combat {
105
105
  * builtin `Combat` class or a custom subclass if that is set up in
106
106
  * {@link ConfiguredCombat | `fvtt-types/configuration/ConfiguredCombat`}.
107
107
  */
108
- type OfType<Type extends SubType> = _OfType[Type];
108
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
109
109
 
110
110
  /** @internal */
111
111
  interface _OfType
@@ -121,7 +121,7 @@ declare namespace Combat {
121
121
  /**
122
122
  * `SystemOfType` returns the system property for a specific `Combat` subtype.
123
123
  */
124
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
124
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
125
125
 
126
126
  /**
127
127
  * @internal
@@ -81,7 +81,7 @@ declare namespace CombatantGroup {
81
81
  * builtin `CombatantGroup` class or a custom subclass if that is set up in
82
82
  * {@link ConfiguredCombatantGroup | `fvtt-types/configuration/ConfiguredCombatantGroup`}.
83
83
  */
84
- type OfType<Type extends SubType> = _OfType[Type];
84
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
85
85
 
86
86
  /** @internal */
87
87
  interface _OfType
@@ -97,7 +97,7 @@ declare namespace CombatantGroup {
97
97
  /**
98
98
  * `SystemOfType` returns the system property for a specific `CombatantGroup` subtype.
99
99
  */
100
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
100
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
101
101
 
102
102
  /**
103
103
  * @internal
@@ -99,7 +99,7 @@ declare namespace Combatant {
99
99
  * builtin `Combatant` class or a custom subclass if that is set up in
100
100
  * {@link ConfiguredCombatant | `fvtt-types/configuration/ConfiguredCombatant`}.
101
101
  */
102
- type OfType<Type extends SubType> = _OfType[Type];
102
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
103
103
 
104
104
  /** @internal */
105
105
  interface _OfType
@@ -115,7 +115,7 @@ declare namespace Combatant {
115
115
  /**
116
116
  * `SystemOfType` returns the system property for a specific `Combatant` subtype.
117
117
  */
118
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
118
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
119
119
 
120
120
  /**
121
121
  * @internal
@@ -91,6 +91,7 @@ declare namespace Folder {
91
91
  * Note that `Folder` does not have a `system` property and therefore there is no way for a user
92
92
  * to configure custom subtypes. See {@linkcode Folder.SubType} for more information.
93
93
  */
94
+ // Note(LukeAbby): The lack of a `system` is why `Document.Internal.DiscriminateSystem` isn't applied.
94
95
  type OfType<Type extends SubType> = _OfType[Type];
95
96
 
96
97
  /** @internal */
@@ -106,7 +106,7 @@ declare namespace Item {
106
106
  * builtin `Item` class or a custom subclass if that is set up in
107
107
  * {@link ConfiguredItem | `fvtt-types/configuration/ConfiguredItem`}.
108
108
  */
109
- type OfType<Type extends SubType> = _OfType[Type];
109
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
110
110
 
111
111
  /** @internal */
112
112
  interface _OfType
@@ -122,7 +122,7 @@ declare namespace Item {
122
122
  /**
123
123
  * `SystemOfType` returns the system property for a specific `Item` subtype.
124
124
  */
125
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
125
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
126
126
 
127
127
  /**
128
128
  * @internal
@@ -98,7 +98,7 @@ declare namespace JournalEntryPage {
98
98
  * {@link ConfiguredJournalEntryPage | `fvtt-types/configuration/ConfiguredJournalEntryPage`}.
99
99
  * up.
100
100
  */
101
- type OfType<Type extends SubType> = _OfType[Type];
101
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
102
102
 
103
103
  /** @internal */
104
104
  interface _OfType
@@ -114,7 +114,7 @@ declare namespace JournalEntryPage {
114
114
  /**
115
115
  * `SystemOfType` returns the system property for a specific `JournalEntryPage` subtype.
116
116
  */
117
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
117
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
118
118
 
119
119
  /**
120
120
  * @internal
@@ -101,6 +101,7 @@ declare namespace Macro {
101
101
  * Note that `Macro` does not have a `system` property and therefore there is no way for a user
102
102
  * to configure custom subtypes. See {@linkcode Macro.SubType} for more information.
103
103
  */
104
+ // Note(LukeAbby): The lack of a `system` is why `Document.Internal.DiscriminateSystem` isn't applied.
104
105
  type OfType<Type extends SubType> = _OfType[Type];
105
106
 
106
107
  /** @internal */
@@ -107,7 +107,7 @@ declare namespace RegionBehavior {
107
107
  * builtin `RegionBehavior` class or a custom subclass if that is set up in
108
108
  * {@link ConfiguredRegionBehavior | `fvtt-types/configuration/ConfiguredRegionBehavior`}.
109
109
  */
110
- type OfType<Type extends SubType> = _OfType[Type];
110
+ type OfType<Type extends SubType> = Document.Internal.DiscriminateSystem<Name, _OfType, Type, ConfiguredSubTypes>;
111
111
 
112
112
  /** @internal */
113
113
  interface _OfType
@@ -123,7 +123,7 @@ declare namespace RegionBehavior {
123
123
  /**
124
124
  * `SystemOfType` returns the system property for a specific `RegionBehavior` subtype.
125
125
  */
126
- type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<_SystemMap, Type>;
126
+ type SystemOfType<Type extends SubType> = Document.Internal.SystemOfType<Name, _SystemMap, Type, ConfiguredSubTypes>;
127
127
 
128
128
  /**
129
129
  * @internal
@@ -95,6 +95,7 @@ declare namespace TableResult {
95
95
  * Note that `TableResult` does not have a `system` property and therefore there is no way for a user
96
96
  * to configure custom subtypes. See {@linkcode TableResult.SubType} for more information.
97
97
  */
98
+ // Note(LukeAbby): The lack of a `system` is why `Document.Internal.DiscriminateSystem` isn't applied.
98
99
  type OfType<Type extends SubType> = _OfType[Type];
99
100
 
100
101
  /** @internal */
@@ -21,9 +21,10 @@ import type {
21
21
  Brand,
22
22
  AnyMutableObject,
23
23
  MaybePromise,
24
- Override,
25
24
  SimpleMerge,
26
25
  PrettifyType,
26
+ AllKeysOf,
27
+ Override,
27
28
  } from "#utils";
28
29
  import type * as CONST from "../constants.mts";
29
30
  import type {
@@ -47,6 +48,7 @@ import type {
47
48
  import type DataModel from "./data.mts";
48
49
  import type DocumentSocketResponse from "./socket.d.mts";
49
50
  import type EmbeddedCollection from "./embedded-collection.d.mts";
51
+ import type { SystemConfig } from "#configuration";
50
52
 
51
53
  export default Document;
52
54
 
@@ -966,8 +968,15 @@ declare namespace Document {
966
968
  | "JournalEntryPage"
967
969
  | "RegionBehavior";
968
970
 
969
- type CoreTypesForName<Name extends Type> = string &
970
- GetKey<Document.MetadataFor<Name>, "coreTypes", [CONST.BASE_DOCUMENT_TYPE]>[number];
971
+ type CoreTypesForName<Name extends Type> = _CoreTypes<
972
+ Name,
973
+ string & GetKey<Document.MetadataFor<Name>, "coreTypes", [CONST.BASE_DOCUMENT_TYPE]>[number]
974
+ >;
975
+
976
+ /** @internal */
977
+ type _CoreTypes<Name extends Type, Types> = SystemConfig extends { [_ in Name]: { readonly base: "ignore" } }
978
+ ? Exclude<Types, "base">
979
+ : Types;
971
980
 
972
981
  type ConfiguredSubTypesOf<Name extends Type> = Name extends "ActorDelta"
973
982
  ? ConfiguredSubTypesOf<"Actor">
@@ -976,12 +985,18 @@ declare namespace Document {
976
985
  // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-duplicate-type-constituents
977
986
  string & (keyof GetKey<DataModelConfig, Name, unknown> | keyof GetKey<SourceConfig, Name, unknown>);
978
987
 
979
- type SubTypesOf<Name extends Type> = Name extends "ActorDelta"
988
+ type SubTypesOf<Name extends Document.Type> = Name extends "ActorDelta"
980
989
  ? SubTypesOf<"Actor">
981
- :
982
- | Document.CoreTypesForName<Name>
983
- | ConfiguredSubTypesOf<Name>
984
- | (Document.MetadataFor<Name> extends { readonly hasTypeData: true } ? Document.ModuleSubType : never);
990
+ : Document.CoreTypesForName<Name> | ConfiguredSubTypesOf<Name> | _ModuleSubType<Name>;
991
+
992
+ /** @internal */
993
+ type _ModuleSubType<Name extends Type> = SystemConfig extends {
994
+ [_ in Name]: { readonly moduleSubType: "ignore" };
995
+ }
996
+ ? never
997
+ : Document.MetadataFor<Name> extends { readonly hasTypeData: true }
998
+ ? Document.ModuleSubType
999
+ : never;
985
1000
 
986
1001
  type ModuleSubType = Brand<`${string}.${string}`, "Document.ModuleSubtype">;
987
1002
 
@@ -1135,19 +1150,31 @@ declare namespace Document {
1135
1150
  GetKey<SourceConfig, Name, {}>
1136
1151
  > &
1137
1152
  // `Document.ModuleSubType` has to be accounted for specially because of its perculiar nature.
1138
- Record<Document.ModuleSubType, UnknownSystem>;
1153
+ Record<Document.ModuleSubType, _ModuleSubTypeFor<Name>>;
1154
+
1155
+ type _ModuleSubTypeFor<Name extends Document.WithSubTypes> = SystemConfig extends {
1156
+ readonly [_ in Name]: { readonly moduleSubtype: "ignore" };
1157
+ }
1158
+ ? never
1159
+ : // The `Extract<..., object>` serves a dual purpose:
1160
+ // 1) Get rid of `| undefined` for optional subtypes.
1161
+ // 2) Make sure it's obvious to TypeScript `system` is always an object.
1162
+ Extract<GetKey<GetKey<DataModelConfig, Name, object>, Document.ModuleSubType, Document.UnknownSystem>, object>;
1139
1163
 
1140
1164
  // Note(LukeAbby): This is written this way to preserve any optional modifiers.
1141
1165
  type _ModelMap<Name extends Document.WithSubTypes, DataModel, Config> = PrettifyType<
1142
1166
  SimpleMerge<
1143
1167
  {
1144
- [SubType in keyof DataModel]: EmptyObject;
1145
- } & {
1146
1168
  [SubType in Document.CoreTypesForName<Name>]: EmptyObject;
1147
1169
  },
1148
- {
1149
- [SubType in keyof Config]: EmptyObject;
1150
- }
1170
+ SimpleMerge<
1171
+ {
1172
+ [SubType in keyof DataModel]: EmptyObject;
1173
+ },
1174
+ {
1175
+ [SubType in keyof Config]: EmptyObject;
1176
+ }
1177
+ >
1151
1178
  >
1152
1179
  >;
1153
1180
 
@@ -1160,31 +1187,47 @@ declare namespace Document {
1160
1187
  GetKey<DataConfig, Name, {}>
1161
1188
  > &
1162
1189
  // `Document.ModuleSubType` has to be accounted for specially because of its perculiar nature.
1163
- Record<Document.ModuleSubType, UnknownSystem>;
1190
+ Record<Document.ModuleSubType, _ModuleSubTypeFor<Name>>;
1164
1191
 
1165
1192
  // Note(LukeAbby): This is written this way to preserve any optional modifiers.
1166
- type _SystemMap<Name extends Document.WithSubTypes, DataModel, Config> = PrettifyType<
1193
+ type _SystemMap<Name extends Document.WithSubTypes, DataModel, DataConfig> = PrettifyType<
1167
1194
  SimpleMerge<
1168
1195
  {
1169
- [SubType in keyof DataModel]: DataModel[SubType] extends
1170
- | (abstract new (...args: never) => infer Model extends DataModel.Any)
1171
- | undefined
1172
- ? Model
1173
- : never;
1174
- } & {
1175
1196
  [SubType in Document.CoreTypesForName<Name>]: EmptyObject;
1176
1197
  },
1177
- {
1178
- [SubType in keyof Config]: Config[SubType];
1179
- }
1198
+ SimpleMerge<
1199
+ {
1200
+ [SubType in keyof DataModel]: DataModel[SubType] extends
1201
+ | (abstract new (...args: never) => infer Model extends DataModel.Any)
1202
+ | undefined
1203
+ ? Model
1204
+ : never;
1205
+ },
1206
+ {
1207
+ [SubType in keyof DataConfig]: DataConfig[SubType];
1208
+ }
1209
+ >
1180
1210
  >
1181
1211
  >;
1182
1212
 
1183
- type SystemOfType<SystemMap extends Record<SubType, object | undefined>, SubType extends string> = SubType extends
1184
- | ModuleSubType
1185
- | "base"
1186
- ? UnknownSystem
1187
- : DiscriminatedUnion<NonNullable<SystemMap[SubType]>>;
1213
+ type SystemOfType<
1214
+ Name extends Document.WithSystem,
1215
+ SystemMap extends Record<SubType, object | undefined>,
1216
+ SubType extends string,
1217
+ ConfiguredSubTypes extends string,
1218
+ > =
1219
+ GetKey<SystemConfig, Name, "none"> extends "discriminateAll"
1220
+ ? _DiscriminateUndefined<SystemMap[SubType]>
1221
+ :
1222
+ | ([Extract<SubType, ConfiguredSubTypes>] extends [never]
1223
+ ? never
1224
+ : _DiscriminateUndefined<SystemMap[Extract<SubType, ConfiguredSubTypes>]>)
1225
+ | ([Exclude<SubType, ConfiguredSubTypes>] extends [never]
1226
+ ? never
1227
+ : SystemMap[Exclude<SubType, ConfiguredSubTypes>]);
1228
+
1229
+ /** @internal */
1230
+ type _DiscriminateUndefined<T extends object | undefined> = DiscriminatedUnion<Exclude<T, undefined>>;
1188
1231
 
1189
1232
  // TODO(LukeAbby): Improve the type display with a helper here.
1190
1233
  // TODO(LukeAbby): Add `StoredSource` for a better type display there.
@@ -1208,6 +1251,52 @@ declare namespace Document {
1208
1251
  get invalid(): true;
1209
1252
  }
1210
1253
 
1254
+ type DiscriminateSystem<
1255
+ Name extends Document.WithSystem,
1256
+ TypeMap extends Record<SubType, { system: object | undefined }>,
1257
+ SubType extends string,
1258
+ ConfiguredSubTypes extends string,
1259
+ > = SystemConfig extends { readonly [_ in Name]: { readonly discriminate: "all" } }
1260
+ ? _DiscriminateSystem<SubType, TypeMap>
1261
+ :
1262
+ | _DiscriminateSystem<Extract<SubType, ConfiguredSubTypes>, TypeMap>
1263
+ | ([Exclude<SubType, ConfiguredSubTypes>] extends [never]
1264
+ ? never
1265
+ : TypeMap[Exclude<SubType, ConfiguredSubTypes>]);
1266
+
1267
+ type _DiscriminateSystem<
1268
+ SubType extends AllSubType,
1269
+ TypeMap extends Record<AllSubType, { system: object | undefined }>,
1270
+ AllSubType extends string = SubType,
1271
+ > = SubType extends unknown ? OfType<SubType, TypeMap, AllSubType> : never;
1272
+
1273
+ // Note(LukeAbby): This is named `OfType` to display as `Document.Internal.OfType` in quick info.
1274
+ interface OfType<
1275
+ OneSubType extends AllSubType,
1276
+ TypeMap extends Record<AllSubType, { system: object | undefined }>,
1277
+ AllSubType extends string,
1278
+ > extends _Override<
1279
+ TypeMap[OneSubType],
1280
+ {
1281
+ system: DiscriminatedSystem<
1282
+ Exclude<TypeMap[OneSubType]["system"], undefined>,
1283
+ Exclude<TypeMap[AllSubType]["system"], undefined>
1284
+ >;
1285
+ }
1286
+ > {}
1287
+
1288
+ // @ts-expect-error This pattern is intrinsically an error.
1289
+ interface _Override<Base extends object, OverrideWith extends object> extends OverrideWith, Base {}
1290
+
1291
+ /** @internal */
1292
+ interface DiscriminatedSystem<System extends object, AllSystem extends object>
1293
+ extends _Override<
1294
+ {
1295
+ [K in AllKeysOf<AllSystem>]?: never;
1296
+ },
1297
+ System
1298
+ > {}
1299
+
1211
1300
  interface DropData<DocumentType extends Document.Type> {
1212
1301
  /**
1213
1302
  * The data used to create a new document.
@@ -5181,7 +5181,8 @@ declare namespace TypeDataField {
5181
5181
  SystemDocumentConstructor extends Document.SystemConstructor,
5182
5182
  Opts extends Options<SystemDocumentConstructor>,
5183
5183
  > = DataField.DerivedInitializedType<
5184
- _Instances<DataModelsFor<SystemDocumentConstructor["metadata"]["name"]>> | Document.UnknownSystem,
5184
+ | _Instances<DataModelsFor<SystemDocumentConstructor["metadata"]["name"]>>
5185
+ | Document.Internal._ModuleSubTypeFor<SystemDocumentConstructor["metadata"]["name"]>,
5185
5186
  MergedOptions<SystemDocumentConstructor, Opts>
5186
5187
  >;
5187
5188
 
@@ -95,6 +95,8 @@ declare abstract class BaseItem<out SubType extends Item.SubType = Item.SubType>
95
95
 
96
96
  type: SubType;
97
97
 
98
+ aaaaa: SubType;
99
+
98
100
  /* Document overrides */
99
101
 
100
102
  // Same as Document for now