store on energy and all resource structures
See original GitHub issueThis is probably a more novice question on typescript. How do you deal with a variable that could be a structure like spawn or storage.
Sample code (if available)
private test(struct: AnyStoreStructure, resource: ResourceConstant) {
const used = struct.store.getUsedCapacity(resource)
}
I get this error due to a structure can be an extension which has a store of Store<RESOURCE_ENERGY, false>;
and storage which has a store of type StoreDefinition = Store<ResourceConstant, false>
I am getting this error with the above code. I am unsure how to allow this the proper way?
[!] (plugin rpt2) Error: D:/programs/screeps-ts-restart/src/departments/shipping.ts(64,39): semantic error TS2349: This expression is not callable.
Each member of the union type '(<R extends "energy" | "power" | "ops" | "U" | "L" | "K" | "Z" | "O" | "H" | "X" | "OH" | "ZK" | "UL" | "G" | "UH" | "UO" | "KH" | "KO" | "LH" | "LO" | "ZH" | "ZO" | "GH" | "GO" | "UH2O" | "UHO2" | ... 58 more ... | undefined = undefined>(resource?: R | undefined) => R extends undefined ? null : R extends "energy" ?...' has signatures, but none of those signatures are compatible with each other.
src\departments\shipping.ts
Error: D:/programs/screeps-ts-restart/src/departments/shipping.ts(64,39): semantic error TS2349: This expression is not callable.
Each member of the union type '(<R extends "energy" | "power" | "ops" | "U" | "L" | "K" | "Z" | "O" | "H" | "X" | "OH" | "ZK" | "UL" | "G" | "UH" | "UO" | "KH" | "KO" | "LH" | "LO" | "ZH" | "ZO" | "GH" | "GO" | "UH2O" | "UHO2" | ... 58 more ... | undefined = undefined>(resource?: R | undefined) => R extends undefined ? null : R extends "energy" ?...' has signatures, but none of those signatures are compatible with each other.
Your Environment
- “@types/screeps”: “^3.1.0”,
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top Results From Across the Web
How Energy Storage Works | Union of Concerned Scientists
Batteries store electricity through electro-chemical processes—converting electricity into chemical energy and back to electricity when needed.
Read more >Pumped Storage Hydropower | Department of Energy
Pumped storage hydropower (PSH ) is a type of hydroelectric energy storage. It is a configuration of two water reservoirs at different elevations...
Read more >Types of energy used in commercial buildings - EIA
Energy use by type of building ; Mercantile and service (15% of total energy consumed by commercial buildings). Malls and stores; Car dealerships...
Read more >Solar Energy | National Geographic Society
Detritivores decompose plant and animal matter by consuming it. ... Photosynthesis is also responsible for all of the fossil fuels on Earth.
Read more >Solar Energy Basics | NREL
Harnesses heat from the sun to provide electricity for large power stations. Additional Resources. For more information about solar energy, visit the following ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@adamtaylor13 Correct. There are certain structures which have stores that can contain any type of resource (ex. Container, Terminal) and then there are structures which have restricted stores (ex. Tower only takes energy). With the current type definitions there just isn’t enough info for the compiler to tell which is which if you have them in a mixed array. Also unfortunately it’s not smart enough to realize energy may be in both sets.
Casting the store as a GenericStore, as you’ve done is the generally acknowledged workaround. The other solution would be to first narrow down the structure types into compatible storage. For example, a
switch
statement testingstructure.StructureType
where eachcase
captures a set of structures with compatible storage, or do it all 1:1. By testing onstructure.structureType
TS should be able to identify the type of the structure, and therefore the type of storage.Screeps is a fun game, and learning TS is a worthy challenge but don’t let the structured nature of it stop you from enjoying the game. If something is really getting you stuck, see if casting it to something (like the generic store type), or worst case
as any
will allow you to keep things moving. Especially since adding 3rd party types to something we can’t control can leave a few rough edges.I highly recommend anyone wanting to play Screeps with TypeScript to join #typescript on the official Discord (recently moved from Slack) https://twitter.com/ScreepsGame/status/1419919747437764612 There is a great community there for TS, other languages, and the game overall.
@pbrink231 @rudykocur Sorry for not getting you this feedback sooner.
I suggest updating the ts version and consider this issue “fixed”. Assuming that is the cause.