typed-factorio 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Changelog.md +16 -0
- package/README.md +25 -28
- package/generated/classes.d.ts +1134 -380
- package/generated/concepts.d.ts +194 -129
- package/generated/defines.d.ts +2 -2
- package/generated/events.d.ts +65 -17
- package/package.json +1 -1
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
|
-
|
74
|
+
Here is a quick overview of type features:
|
75
75
|
|
76
|
-
|
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
|
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
|
-
###
|
82
|
+
### Parameter Variants
|
91
83
|
|
92
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
-
###
|
103
|
+
### Classes with subclasses
|
115
104
|
|
116
|
-
Some classes have attributes that are documented to only work
|
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
|
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`.
|
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.
|