typed-factorio 2.8.0 → 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -10,7 +10,8 @@ The generator uses both the Factorio api docs JSON and manually defined addition
10
10
  To use in your [TypescriptToLua](https://typescripttolua.github.io/) project:
11
11
 
12
12
  1. Install this package: `npm install typed-factorio`
13
- - Note: When types are updated for a new factorio version, you will need to update this package.
13
+
14
+ - Note: When types are updated for a new factorio version, you will need to update this package.
14
15
 
15
16
  2. Add types for the [stages](https://lua-api.factorio.com/1.1.89/index.html) used to `tsconfig.json > compilerOptions > types`.
16
17
  The available stages are `"typed-factorio/settings"`, `"typed-factorio/prototype"`, and `"typed-factorio/runtime"`.
@@ -35,7 +36,8 @@ Here are some notes on using the types:
35
36
 
36
37
  ### Types for other stages
37
38
 
38
- No matter which stage(s) are selected, _type_ definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
39
+ 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
+
39
41
  ```ts
40
42
  import { BoolSettingDefinition } from "factorio:settings"
41
43
  import { ItemPrototype } from "factorio:prototype"
@@ -45,40 +47,46 @@ import { LuaEntity } from "factorio:runtime"
45
47
  You can also include just `"typed-factorio"` in your `types` field. This will include only global variables available to _all_ stages.
46
48
 
47
49
  ### `data.extend()` types
48
- In the settings and prototype stages, the `data` global variable is available.
50
+
51
+ In the settings and prototype stages, the `data` global variable is available.
49
52
 
50
53
  For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is by default loosely typed.
51
54
  To get full type checking, you can use specific types in one of the following ways:
55
+
52
56
  ```ts
53
57
  // Use `satisfies` to check types:
54
58
  data.extend([
55
- {
56
- type: "ammo-category",
57
- name: "foo",
58
- } satisfies AmmoCategory,
59
- {
60
- type: "item",
61
- name: "bar",
62
- // ...other fields
63
- } satisfies ItemPrototype,
59
+ {
60
+ type: "ammo-category",
61
+ name: "foo",
62
+ } satisfies AmmoCategory,
63
+ {
64
+ type: "item",
65
+ name: "bar",
66
+ // ...other fields
67
+ } satisfies ItemPrototype,
64
68
  ])
65
69
 
66
70
  // List types as a type argument to `extend`:
67
71
  data.extend<AmmoCategory | ItemPrototype>([
68
- {
69
- type: "ammo-category",
70
- name: "foo"
71
- },
72
- {
73
- type: "item",
74
- name: "bar",
75
- // ...other fields
76
- }
72
+ {
73
+ type: "ammo-category",
74
+ name: "foo",
75
+ },
76
+ {
77
+ type: "item",
78
+ name: "bar",
79
+ // ...other fields
80
+ },
77
81
  ])
78
82
 
79
83
  // Use types on separate variables:
80
- const fooCategory: AmmoCategory = {/* ... */}
81
- const barItem: ItemPrototype = {/* ... */}
84
+ const fooCategory: AmmoCategory = {
85
+ /* ... */
86
+ }
87
+ const barItem: ItemPrototype = {
88
+ /* ... */
89
+ }
82
90
  data.extend([fooCategory, barItem])
83
91
  ```
84
92
 
@@ -149,6 +157,7 @@ Event IDs (`defines.events`) hold type info for their corresponding event type a
149
157
  You can pass an event data type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that includes type info.
150
158
 
151
159
  ### Optional custominput name checking
160
+
152
161
  You can optionally enable type-checking for custom input names (for `script.on_event` and `CustomInputPrototype`).
153
162
  To do so, specify names by extending the CustomInputNames interface like so:
154
163
 
@@ -159,7 +168,7 @@ declare module "factorio:common" {
159
168
  }
160
169
  }
161
170
 
162
- script.on_event("my-custom-input", ()=>{}) // type-checked
171
+ script.on_event("my-custom-input", () => {}) // type-checked
163
172
  ```
164
173
 
165
174
  If not specified, `CustomInputName` defaults to just `string`.
@@ -201,11 +210,8 @@ Similarly, `GuiSpec` (the table passed to `LuaGuiElement.add`), is also a discri
201
210
 
202
211
  This is done both to provide more accurate types, and for possible integration with [JSX](https://typescripttolua.github.io/docs/jsx/).
203
212
 
204
-
205
213
  ## Support
206
214
 
207
215
  If you find this project useful, consider tipping me on Kofi!
208
216
 
209
217
  <a href='https://ko-fi.com/Z8Z1VI6P8' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
210
-
211
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-factorio",
3
- "version": "2.8.0",
3
+ "version": "2.10.1",
4
4
  "description": "Featureful typescript definitions for the Factorio modding api.",
5
5
  "keywords": [
6
6
  "factorio",
@@ -26,7 +26,7 @@
26
26
  "generate-no-format": "tsx --tsconfig generator/tsconfig.json generator/main.ts --no-format",
27
27
  "clean": "rimraf runtime/generated prototype/generated",
28
28
  "lint": "eslint .",
29
- "check": "tsc --noEmit && npm run lint",
29
+ "check": "tsc --noEmit && npm run lint && prettier --check .",
30
30
  "prepublishOnly": "npm run generate && npm run check",
31
31
  "script": "tsx --tsconfig scripts/tsconfig.json",
32
32
  "download-latest-json-apis": "npm run script ./scripts/download-latest.ts",