typed-factorio 3.19.0 → 3.19.2

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/README.md CHANGED
@@ -4,18 +4,17 @@
4
4
 
5
5
  Complete and featureful typescript definitions for the Factorio modding lua API, for use with [TypescriptToLua](https://typescripttolua.github.io/).
6
6
 
7
- This project aims to provide type definitions are as complete as possible.
8
- The generator uses both the Factorio api docs JSON and manually defined additions.
7
+ This project aims to provide type definitions that are as complete as possible.
9
8
 
10
9
  ## Installation
11
10
 
12
11
  To use in your [TypescriptToLua](https://typescripttolua.github.io/) project:
13
12
 
14
- 1. Install this package: `npm install typed-factorio`
13
+ 1. Install this package: `npm install --save-dev typed-factorio`
15
14
 
16
- - Note: When types are updated for a new factorio version, you will need to update this package.
15
+ > Note: When types are updated for a new factorio version, you will need to update this package.
17
16
 
18
- 2. Add types for the [stages](https://lua-api.factorio.com/1.1.89/index.html) used to `tsconfig.json > compilerOptions > types`.
17
+ 2. Add types for the [Factorio stages](https://lua-api.factorio.com/latest) used to your `tsconfig.json` under `compilerOptions > types`.
19
18
  The available stages are `"typed-factorio/settings"`, `"typed-factorio/prototype"`, and `"typed-factorio/runtime"`.
20
19
 
21
20
  Example:
@@ -29,16 +28,16 @@ Example:
29
28
  }
30
29
  ```
31
30
 
32
- The stages used will select the global variables defined.
33
- You can include multiple stages, but there are some caveats. See [Using multiple stages in the same project](#using-multiple-loading-stages-in-the-same-project) for more info.
31
+ Each stage will define the global variables used in that stage.
32
+ You can include multiple stages, but there are some caveats. For more info, see [Using multiple stages in the same project](#using-multiple-loading-stages-in-the-same-project).
34
33
 
35
34
  ## Usage notes
36
35
 
37
- Here are some notes on using the types:
36
+ Some more info on using types.
38
37
 
39
38
  ### Types for other stages
40
39
 
41
- No matter which stage(s) are selected, _type_ definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
40
+ No matter which stage(s) are selected, type definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
42
41
 
43
42
  ```ts
44
43
  import { BoolSettingDefinition } from "factorio:settings"
@@ -46,14 +45,39 @@ import { ItemPrototype } from "factorio:prototype"
46
45
  import { LuaEntity } from "factorio:runtime"
47
46
  ```
48
47
 
49
- You can also include just `"typed-factorio"` in your `types` field. This will include only global variables available to _all_ stages.
48
+ You can also include just `"typed-factorio"` in your tsconfig's `types`. This will define only global variables that are available to _all_ stages.
50
49
 
51
- ### `data.extend()` types
50
+ ### The `storage` table
51
+
52
+ The `storage` table (in the runtime stage) can have any shape, so it is not defined here. Instead, you can define it yourself:
53
+
54
+ - Add `declare const storage: <Your type>` in a `.d.ts` file. Make sure this file is included by your tsconfig!
55
+ - Add `declare global { const storage: <Your type> }` in a `.ts` file included in your project.
56
+ - Add `declare const storage: {...}` to each file where needed. This way, you can define only properties that each file specifically uses.
57
+
58
+ ### Factorio lualib modules
59
+
60
+ There are types for the following [Factorio lualib modules](https://github.com/wube/factorio-data/tree/master/core/lualib):
61
+
62
+ - `util`
63
+ - `mod-gui`
64
+
65
+ These can be imported as modules:
66
+
67
+ ```ts
68
+ import * as util from "util"
69
+
70
+ const foo = util.copy(bar)
71
+ ```
72
+
73
+ If you wish to see types for more lualib modules, feel free to open an issue or pull request.
74
+
75
+ ### Types for `data.extend()`
52
76
 
53
77
  In the settings and prototype stages, the `data` global variable is available.
54
78
 
55
79
  For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is by default loosely typed.
56
- To get full type checking, you can use specific types in one of the following ways:
80
+ To get full strict type checking, you can use one of the following methods:
57
81
 
58
82
  ```ts
59
83
  // Use `satisfies` to check types:
@@ -69,7 +93,7 @@ data.extend([
69
93
  } satisfies ItemPrototype,
70
94
  ])
71
95
 
72
- // List types as a type argument to `extend`:
96
+ // List types used as a type argument to `extend`:
73
97
  data.extend<AmmoCategory | ItemPrototype>([
74
98
  {
75
99
  type: "ammo-category",
@@ -92,31 +116,6 @@ const barItem: ItemPrototype = {
92
116
  data.extend([fooCategory, barItem])
93
117
  ```
94
118
 
95
- ### Factorio lualib modules
96
-
97
- There are types for the following [Factorio lualib modules](https://github.com/wube/factorio-data/tree/master/core/lualib):
98
-
99
- - `util`
100
- - `mod-gui`
101
-
102
- These can be imported as modules:
103
-
104
- ```ts
105
- import * as util from "util"
106
-
107
- const foo = util.copy(bar)
108
- ```
109
-
110
- If you wish to see types for more lualib modules, feel free to open an issue or pull request.
111
-
112
- ### The `storage` table
113
-
114
- The `storage` table (in the runtime stage) can have any shape, so it is not defined here. Instead, you can define it yourself:
115
-
116
- - Add `declare const storage: <Your type>` in a `.d.ts` file. Make sure this file is included by your tsconfig!
117
- - Add `declare global { const storage: <Your type> }` in a `.ts` file included in your project.
118
- - Add `declare const storage: {...}` to each file where needed. This way, you can define only properties that each file specifically uses.
119
-
120
119
  ## Using multiple loading stages in the same project
121
120
 
122
121
  Every Factorio loading stage declares different global variables.
@@ -157,11 +156,11 @@ Parameter tables with variants (having "additional attributes can be specified d
157
156
 
158
157
  ### Events
159
158
 
160
- Event IDs (`defines.events`) hold type info for their corresponding event type and filters, which is used by various methods in `script`.
159
+ Event IDs (`defines.events`) hold type info on their corresponding event data type and filters, which is used by various methods in `script`.
161
160
 
162
- You can pass an event data type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that includes type info.
161
+ You can pass a type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that includes type info.
163
162
 
164
- ### Optional custominput name checking
163
+ ### Optional CustomInput name checking
165
164
 
166
165
  You can optionally enable type-checking for custom input names (for `script.on_event` and `CustomInputPrototype`).
167
166
  To do so, specify names by extending the CustomInputNames interface like so:
@@ -174,27 +173,29 @@ declare module "factorio:common" {
174
173
  }
175
174
 
176
175
  script.on_event("my-custom-input", () => {}) // type-checked
176
+ // script.on_event("my-customm-input", () => {}) // mispelled, will error
177
177
  ```
178
178
 
179
- If not specified, `CustomInputName` defaults to just `string`.
179
+ The type `CustomInputName` (not plural) will be a union of strings, for all custom input names.
180
+ If not specified like above, `CustomInputName` defaults to just `string`.
180
181
 
181
182
  ### Array-like classes
182
183
 
183
- Classes that have an index operator, a length operator, and have an array-like structure subclass from `(Readonly)Array`. These are `LuaInventory`, `LuaFluidBox`, `LuaTransportLine`.
184
+ A few classes that have an index operator, a length operator, and have an array-like structure, which will subclass from `(Readonly)Array`. These are `LuaInventory`, `LuaFluidBox`, `LuaTransportLine`.
184
185
  This allows you to use these classes like arrays, e.g. having array methods and `.length` translating to the lua length operator. However, this means like typescript arrays, they are **0-indexed, not 1-indexed**.
185
186
 
186
187
  ### Read and write variants
187
188
 
188
- For concepts that can take a table or array form, the main type (e.g. `MapPosition`) defines the table form, and an `Array` suffix (e.g. `MapPositionArray`) defines the array form.
189
- Concepts in a "read" position are in table form, and concepts in a "write" position may be either in table or array form (e.g. `MapPosition | MapPositionArray`).
189
+ For concepts that can take a table-or-array form, the main type (e.g. `MapPosition`) defines the table form, and a type suffixed with `Array` (e.g. `MapPositionArray`) defines the array form.
190
+ Concepts in a "read" position are in table form. Concepts in a "write" position may be in either table or array form (e.g. `MapPosition | MapPositionArray`).
190
191
  Concepts that include table-or-array concepts may have an additional `Write` variant (e.g. `ScriptArea`, `ScriptAreaWrite`).
191
192
 
192
193
  ### Classes with subclasses
193
194
 
194
- Some classes have attributes that only work for particular subclasses. For these classes (e.g. `LuaEntity`) there are specific types that you can _optionally_ use:
195
+ Some classes have attributes that only work for particular subclasses (e.g. LuaEntity.recipe only works if this is crafting-machine). For these classes, there are more specific types you can _optionally_ use:
195
196
 
196
197
  - A "Base" type (e.g. `BaseEntity`) which contains only members usable by all subclasses
197
- - Multiple subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass.
198
+ - Subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass.
198
199
 
199
200
  The original class name (e.g. `LuaEntity`) contains attributes for _all_ subclasses.
200
201
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-factorio",
3
- "version": "3.19.0",
3
+ "version": "3.19.2",
4
4
  "description": "Featureful typescript definitions for the Factorio modding api.",
5
5
  "keywords": [
6
6
  "factorio",
@@ -16,7 +16,6 @@
16
16
  "license": "MIT",
17
17
  "files": [
18
18
  "**/*.d.ts",
19
- "*.d.ts",
20
19
  "!generator/**/*"
21
20
  ],
22
21
  "type": "module",
@@ -4326,14 +4326,14 @@ declare module "factorio:runtime" {
4326
4326
  * Only entities inheriting from {@link import("factorio:prototype").EntityWithOwnerPrototype EntityWithOwnerPrototype}, as well as {@link import("factorio:prototype").ItemRequestProxyPrototype ItemRequestProxyPrototype} and {@link import("factorio:prototype").EntityGhostPrototype EntityGhostPrototype} are assigned a unit number. Returns `nil` otherwise.
4327
4327
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.unit_number Online documentation}
4328
4328
  */
4329
- readonly unit_number?: uint64
4329
+ readonly unit_number?: UnitNumber
4330
4330
  /**
4331
4331
  * The {@link LuaEntity#unit_number unit_number} of the entity contained in this ghost. It is the same as the unit number of the {@link import("factorio:prototype").EntityWithOwnerPrototype EntityWithOwnerPrototype} that was destroyed to create this ghost. If it was created by other means, or if the inner entity does not support unit numbers, this property is `nil`.
4332
4332
  *
4333
4333
  * _Can only be used if this is EntityGhost_
4334
4334
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.ghost_unit_number Online documentation}
4335
4335
  */
4336
- readonly ghost_unit_number?: uint64
4336
+ readonly ghost_unit_number?: UnitNumber
4337
4337
  /**
4338
4338
  * The mining progress for this mining drill. Is a number in range [0, mining_target.prototype.mineable_properties.mining_time]. `nil` if this isn't a mining drill.
4339
4339
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.mining_progress Online documentation}
@@ -5972,7 +5972,7 @@ declare module "factorio:runtime" {
5972
5972
  * Only entities inheriting from {@link import("factorio:prototype").EntityWithOwnerPrototype EntityWithOwnerPrototype}, as well as {@link import("factorio:prototype").ItemRequestProxyPrototype ItemRequestProxyPrototype} and {@link import("factorio:prototype").EntityGhostPrototype EntityGhostPrototype} are assigned a unit number. Returns `nil` otherwise.
5973
5973
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.unit_number Online documentation}
5974
5974
  */
5975
- readonly unit_number?: uint64
5975
+ readonly unit_number?: UnitNumber
5976
5976
  /**
5977
5977
  * The mining progress for this mining drill. Is a number in range [0, mining_target.prototype.mineable_properties.mining_time]. `nil` if this isn't a mining drill.
5978
5978
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.mining_progress Online documentation}
@@ -6240,7 +6240,7 @@ declare module "factorio:runtime" {
6240
6240
  * _Can only be used if this is EntityGhost_
6241
6241
  * @see {@link https://lua-api.factorio.com/2.0.44/classes/LuaEntity.html#LuaEntity.ghost_unit_number Online documentation}
6242
6242
  */
6243
- readonly ghost_unit_number?: uint64
6243
+ readonly ghost_unit_number?: UnitNumber
6244
6244
  }
6245
6245
  /**
6246
6246
  * @noSelf
@@ -35,7 +35,7 @@ declare module "factorio:runtime" {
35
35
  *
36
36
  * You can cast a raw number to this type, e.g. `1 as UnitNumber`.
37
37
  */
38
- type UnitNumber = uint & {
38
+ type UnitNumber = uint64 & {
39
39
  _unitNumberBrand: void
40
40
  }
41
41
  /**