typed-factorio 0.15.0 → 0.16.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,8 @@
1
+ # v0.16.0
2
+
3
+ - `LuaCustomTable` can be iterated on in a for-of loop directly (without using `pairs`). This requires TSTL v1.3.0 or later.
4
+ - TSTL dependency minimum version is now v1.3.0.
5
+
1
6
  # v0.15.0
2
7
 
3
8
  - Table or array concepts are now declared in table form wherever it is an "read" position.
@@ -7,7 +12,7 @@
7
12
  - Arrays which are known to be in a "write" only form (e.g. method parameters) now are marked readonly. This means you can now pass readonly-only arrays to these methods.
8
13
  - `MapPosition` is now a table or array concept.
9
14
  - Classes with subclasses are now declared with all properties, instead of an intersection of subclasses (reversion)
10
- - Subclass specializations are added for some missing classes
15
+ - Subclass specializations added for some missing classes
11
16
 
12
17
  # v0.14.1
13
18
 
package/README.md CHANGED
@@ -73,7 +73,7 @@ The `global` table is just a lua table which can have any shape the mod desires,
73
73
 
74
74
  Typed-factorio has 100% complete types for the runtime stage. Description-only concepts and some not documented types are filled in manually.
75
75
 
76
- Here are some details on particular type features in the definitions:
76
+ Here are some details on particular type features:
77
77
 
78
78
  ### Lua features
79
79
 
@@ -96,6 +96,7 @@ The type for a specific variant is prefixed with the variant name, or with "Othe
96
96
  ### Types with subclasses
97
97
 
98
98
  Some classes have attributes that are documented to only work on particular subclasses. For these classes, e.g. `LuaEntity`, there are also these other types that you can _optionally_ use:
99
+
99
100
  - a "Base" type, e.g. `BaseEntity`, which only contains members usable by all subclasses
100
101
  - individual subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass
101
102
 
@@ -111,9 +112,13 @@ You can pass a type parameter to `script.generate_event_name<T>()`, and it will
111
112
 
112
113
  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**.
113
114
 
114
- ### Table or array types
115
+ ### Table or array types, and "Read" concepts
116
+
117
+ 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.
118
+
119
+ 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.
115
120
 
116
- 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 specifically.
121
+ 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`.
117
122
 
118
123
  ### LuaGuiElement
119
124
 
@@ -1939,7 +1939,7 @@ interface LuaCustomInputPrototype {
1939
1939
  help(): string
1940
1940
  }
1941
1941
 
1942
- type CustomTableIndex<K extends keyof any, V>
1942
+ type CustomTableIndex<K extends string | number, V>
1943
1943
  /**
1944
1944
  * Access an element of this custom table.
1945
1945
  *
@@ -2012,7 +2012,9 @@ interface LuaCustomTableMembers {
2012
2012
  * global.p = game.players -- This has high potential to make the game unsaveable
2013
2013
  * ```
2014
2014
  */
2015
- type LuaCustomTable<K extends keyof any, V> = LuaCustomTableMembers & CustomTableIndex<K, V>
2015
+ type LuaCustomTable<K extends string | number, V> = LuaCustomTableMembers &
2016
+ CustomTableIndex<K, V> &
2017
+ LuaPairsIterable<[number] extends [K] ? number : K, V>
2016
2018
 
2017
2019
  /**
2018
2020
  * Prototype of a damage.
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "typed-factorio",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Featureful typescript definitions for the the Factorio modding lua api.",
5
5
  "keywords": [
6
- "factorio", "types", "typescript-to-lua", "tstl"
6
+ "factorio",
7
+ "types",
8
+ "typescript-to-lua",
9
+ "tstl"
7
10
  ],
8
11
  "repository": "https://github.com/GlassBricks/typed-factorio",
9
12
  "license": "MIT",
@@ -25,7 +28,7 @@
25
28
  },
26
29
  "peerDependencies": {
27
30
  "lua-types": "^2.11.0",
28
- "typescript-to-lua": "^1.0.0"
31
+ "typescript-to-lua": "^1.3.1"
29
32
  },
30
33
  "devDependencies": {
31
34
  "@types/jest": "^27.0.3",
@@ -50,6 +53,6 @@
50
53
  "ts-jest": "^27.1.0",
51
54
  "ts-node": "^10.4.0",
52
55
  "typescript": "4.5.2",
53
- "typescript-to-lua": "^1.2.0"
56
+ "typescript-to-lua": "^1.3.1"
54
57
  }
55
58
  }
@@ -1,13 +1,14 @@
1
1
  /** @noSelfInFile */
2
2
 
3
- /** Iterating with `pairs` will only iterate the array part of a {@link LuaCustomTable}. */
4
- declare function pairs<V>(table: LuaCustomTable<number | string, V>): LuaIterable<LuaMultiReturn<[number, V]>>
5
-
6
- declare function pairs<K extends keyof any, V>(table: LuaCustomTable<K, V>): LuaIterable<LuaMultiReturn<[K, V]>>
7
-
8
3
  /**
9
- * {@link LuaCustomTable} cannot be iterated with `ipairs`. Use `pairs` instead.
4
+ * Iterating with `pairs` will only iterate the array part of a {@link LuaCustomTable}.
10
5
  *
11
- * @deprecated
6
+ * **Note**: you can also iterate on a LuaCustomTable directly without using `pairs`, e.g. `for(const [k, v] of table)`.
12
7
  */
8
+ declare function pairs<V>(table: LuaCustomTable<number | string, V>): LuaIterable<LuaMultiReturn<[number, V]>>
9
+
10
+ /** **Note**: you can also iterate on a LuaCustomTable directly without using `pairs`, e.g. `for(const [k, v] of table)`. */
11
+ declare function pairs<K extends number | string, V>(table: LuaCustomTable<K, V>): LuaIterable<LuaMultiReturn<[K, V]>>
12
+
13
+ /** @deprecated {@link LuaCustomTable} cannot be iterated with `ipairs`; Use {@link pairs} instead. */
13
14
  declare function ipairs(table: LuaCustomTable<any, any>): never