typed-factorio 2.5.0 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
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` 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.2",
4
4
  "description": "Featureful typescript definitions for the Factorio modding api.",
5
5
  "keywords": [
6
6
  "factorio",