typed-factorio 1.3.0 → 1.4.0

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/Changelog.md CHANGED
@@ -1,3 +1,19 @@
1
+ # v1.4.0
2
+
3
+ - Improve doc comments for enum concepts
4
+ - Improve doc comment formatting
5
+ - Improve types of concepts with literal union types
6
+ - Add read-specific types to AutoplaceControl and ComparatorString
7
+
8
+ # v1.3.2
9
+
10
+ - Move "notes" comment into the main body of doc comment, instead of in @remarks. This works around #13.
11
+ - Add manually defined overload for LuaControl::teleport().
12
+
13
+ # v1.3.1
14
+
15
+ - Use @linkplain instead of @link for web links. This hopefully works around issue #13
16
+
1
17
  # v1.3.0
2
18
 
3
19
  - Updated to factorio version 1.1.61
package/README.md CHANGED
@@ -71,54 +71,52 @@ The `global` table is just a lua table which can have any shape the mod desires,
71
71
 
72
72
  ## Type features
73
73
 
74
- Typed-factorio has 100% complete types for the runtime stage. Description-only concepts and some not documented types are filled in manually.
74
+ Here is a quick overview of type features:
75
75
 
76
- Here are some details on particular type features:
77
-
78
- ### Lua features
79
-
80
- The types include [TypescriptToLua language extensions](https://typescripttolua.github.io/docs/advanced/language-extensions/)
81
- and [lua-types](https://github.com/TypeScriptToLua/lua-types) (for v5.2) as dependencies.
82
-
83
- ### `nil`
76
+ ### Nullability
84
77
 
85
78
  The types consistently use `undefined` to represent `nil`.
86
- `null` is not used, because `undefined` in typescript is much more similar to `nil` in lua, and optional parameters/properties already use `undefined`.
87
79
 
88
- A class attribute is marked as possibly undefined only if the _read_ type is possibly `nil`. For properties where `nil` is not possible on _read_, but is possible on _write_, you can write `nil` by using `undefined!` or `myNullableValue!`, e.g. `controlBehavior.parameters = undefined!`.
80
+ A class attribute is marked as possibly undefined only if the _read_ type is possibly `nil`. For properties where `nil` is not possible on _read_, but possible on _write_, you can write `nil` by using `undefined!` or `myNullableValue!`, e.g. `controlBehavior.parameters = undefined!`.
89
81
 
90
- ### Variant parameter types
82
+ ### Parameter Variants
91
83
 
92
- Variant parameter types (types with "additional fields can be specified depending on type") are handled as a union of all variants (which is often a [discriminated union](https://basarat.gitbook.io/typescript/type-system/discriminated-unions#discriminated-union)). This gives proper type checking for each variant.
93
-
94
- The type for a specific variant is prefixed with the variant name, or with "Other" for variants without additional fields (e.g. `AmmoDamageTechnologyModifier`, `OtherTechnologyModifier`).
84
+ Parameters with variants (with "additional fields can be specified depending on type ...") are defined as a union of all variants. The type for a specific variant is prefixed with the variant name, or "Other" types variants without extra properties (e.g. `AmmoDamageTechnologyModifier`, `OtherTechnologyModifier`).
95
85
 
96
86
  ### Events
97
87
 
98
- `script.on_event()`, `script.get/set_filters()`, and `script.raise_event()` all have type checking on the event data/filter type, inferred from what is passed as the event name/id.
99
-
100
- You can pass a type parameter to `script.generate_event_name<T>()`, and it will return an `EventId` that holds type info of the event data. Event functions on `script` can then use the type data when the `EventId` is passed.
88
+ Event IDs (`defines.events`) carry information about their event type and possible filters, which is used by the various methods on `script`.
89
+ You can pass a type parameter to `script.generate_event_name<T>()`, and it will return an `EventId` that holds type info of the event data.
101
90
 
102
- ### Array-like types
91
+ ### Array-like classes
103
92
 
104
93
  Classes that have an index operator, a length operator, and have an array-like structure, inherit from `(Readonly)Array`. These are `LuaInventory`, `LuaFluidBox`, `LuaTransportLine`. This allows you to use these classes like arrays, meaning having array methods, and `.length` translating to the lua length operator. However, this also means, like typescript arrays, they are **0-indexed, not 1-indexed**.
105
94
 
106
- ### Table or array types, and "Read" concepts
95
+ ### Table-or-array concepts, and "Read" variants
107
96
 
108
97
  For table-or-array types (e.g. Position), there also are types such as `PositionTable` and `PositionArray` that refer to the table or array form.
109
98
 
110
- Table-or-array types will appear in the Table form when known to be in a read position. This also applies to other concepts/complex types that have table-or-array attributes.
99
+ Table-or-array types will appear in Table form when known to be in a read position. This also applies to other concepts/types that have table-or-array attributes.
111
100
 
112
- For some concepts, there is also a special form for when the concept is used in a "read" position, where all table-or-array types are in Table form. These types are suffixed with `Read`, e.g. `ScriptPositionRead`.
101
+ For some concepts, there is also a special form for when it is used in a "read" position, where all table-or-array types are in Table form. These types are suffixed with `Read`, e.g. `ScriptPositionRead`, `BoundingBoxRead`.
113
102
 
114
- ### Types with subclasses
103
+ ### Classes with subclasses
115
104
 
116
- Some classes have attributes that are documented to only work on particular subclasses. For these classes, e.g. `LuaEntity`, there are specific types that you can _optionally_ use:
105
+ Some classes have attributes that are documented to only work for particular subclasses. For these classes, e.g. `LuaEntity`, there are specific types that you can _optionally_ use:
117
106
 
118
107
  - a "Base" type, e.g. `BaseEntity`, which only contains members usable by all subclasses
119
- - individual subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass
108
+ - individual subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass.
120
109
 
121
- The simple class name, `LuaEntity` in this example, contains attributes for _all_ subclasses.
110
+ The simple class name, e.g. `LuaEntity`, contains attributes for _all_ subclasses.
111
+
112
+ For stricter types, use the `Base` type generally, and the specific subclass type when needed.
113
+ You can also create your own type-narrowing functions, like so:
114
+
115
+ ```ts
116
+ function isCraftingMachineEntity(entity: LuaEntity): entity is CraftingMachineEntity {
117
+ return entity.type === "crafting-machine"
118
+ }
119
+ ```
122
120
 
123
121
  ### LuaGuiElement
124
122
 
@@ -132,7 +130,6 @@ This is done both to provide more accurate types, and for possible integration w
132
130
 
133
131
  This is a recommended **opt-in** feature. To opt in, add `"typed-factorio/strict-index-types"` to `compilerOptions > types` in your tsconfig.json (in addition to `"typed-factorio/runtime"`).
134
132
 
135
- Some `uint` types which represent indices, e.g. player_index, entity_number, can be "branded" numbers with their own type, e.g. `PlayerIndex` and `EntityNumber`. These are assignable to `number`, but a plain `number` is not directly assignable to them. This helps ensure correctness.
136
- These are indices that do not index into an array-like structure, and otherwise should usually not have arithmetic done to them.
133
+ Some `uint` types which represent unique indices, e.g. player_index, entity_number, can be "branded" numbers with their own type, e.g. `PlayerIndex` and `EntityNumber`. If opted-in, these index-types will be still assignable to `number`, but a plain `number` is not directly assignable to them. This helps ensure correctness.
137
134
  You can use these types as keys in an index signature, e.g. `{ [index: PlayerIndex]: "foo" }`.
138
135
  You can cast "plain" numbers to these types, e.g. `1 as PlayerIndex`, do this with caution.