typed-factorio 2.5.0 → 2.5.1

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.
Files changed (2) hide show
  1. package/README.md +22 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -41,15 +41,13 @@ import { ItemPrototype } from "factorio:prototype"
41
41
  import { LuaEntity } from "factorio:runtime"
42
42
  ```
43
43
 
44
- ### Data.extend
44
+ ### `data.extend()`
45
45
  In the settings and prototype stages, the `data` global variable is available.
46
46
 
47
- For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is only loosely typed.
48
- To get full type checking, use specific types when adding prototypes:
47
+ For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is by default loosely typed.
48
+ To get full type checking, you can use specific types in one of the following ways:
49
49
  ```ts
50
- // example: adding an ammo category and item prototype
51
- import { AmmoCategory, ItemPrototype } from "factorio:prototype"
52
-
50
+ // Use `satisfies` on types to check types
53
51
  data.extend([
54
52
  {
55
53
  type: "ammo-category",
@@ -58,10 +56,27 @@ data.extend([
58
56
  {
59
57
  type: "item",
60
58
  name: "bar",
61
- // other fields...
59
+ // ...other fields
62
60
  } satisfies ItemPrototype,
63
61
  ])
64
62
 
63
+ // List types as a type argument to `extend`:
64
+ data.extend<AmmoCategory | ItemPrototype>([
65
+ {
66
+ type: "ammo-category",
67
+ name: "foo"
68
+ },
69
+ {
70
+ type: "item",
71
+ name: "bar",
72
+ // ...other fields
73
+ }
74
+ ])
75
+
76
+ // Use types on separate variables:
77
+ const fooCategory: AmmoCategory = {/* ... */}
78
+ const barItem: ItemPrototype = {/* ... */}
79
+ data.extend([fooCategory, barItem])
65
80
  ```
66
81
 
67
82
  ### Factorio lualib modules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-factorio",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Featureful typescript definitions for the Factorio modding api.",
5
5
  "keywords": [
6
6
  "factorio",