Comments (3)
I've noticed that changing the hash type does negatively affect loops. When iterating over, e.g., Game.rooms
, we know that all of the elements will not be undefined
. But this is not expressed by the type { [roomName: string]: Room | undefined }
, which describes elements which can be a Room
or undefined
in all contexts, in lookups, iteration, etc.
Fixing it requires temporarily overriding the type, which is pretty ugly:
// Find all controlled and claimed rooms
const claimedRooms = _.filter(Game.rooms as {[roomName: string]: Room}, (room) => {
return room.controller && room.controller.my;
});
(The type of claimedRooms
is then {[roomName: string]: Room}
which then kind of goes back to the original problem if I want to do lookups on this new hash.)
I also found this discussion about pretty much the same thing in the TpyeScript repo:
microsoft/TypeScript#9235
microsoft/TypeScript#7140 (comment)
So I don't think my approach in #108 is really workable anymore. I don't really want to model a hash with undefined
elements. I think what I'm really looking for is to just change the type of the hash lookup function. But I don't think it's really possible in TypeScript right now.
from typed-screeps.
You can use https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
from typed-screeps.
Can we close this?
from typed-screeps.
Related Issues (20)
- error using look constants `creep.pos.lookFor(LOOK_TERRAIN)` HOT 1
- Migrate from Travis CI to Github Actions HOT 1
- Season 1 HOT 1
- season2 SymbolDecoder HOT 1
- store on energy and all resource structures HOT 11
- `OBSTACLE_OBJECT_TYPES` causes `includes` argument to be too narrow, defeating the purpose of it existing. HOT 1
- Publish non-global version of definitions HOT 3
- Missing undefined return type for CostMatrix#get
- Argument in the filter function of `findClosestByRange` can not be inferred
- Introduce some util types for writing test cases HOT 1
- Memory is constant and therefore throws an error when trying to assign to it HOT 1
- Rollback breaking change on `Game.getObjectById` to follow Semantic Versioning HOT 2
- Add a new subset of `AnyOwnedStructures`, excluding `KeeperLairs`, etc.
- Refactor find* methods. Part 1/3 : Decoupling `FilterOption` and `FindConstant`
- Refactor find* methods. Part 2/3 : Ban random cast from results of `find*()`
- Refactor find* methods. Part 3/3 : Ban `find<StructureType>()`
- `Spawning.directions` can be undefined HOT 1
- add _bits to CostMatrix
- Result of room.lookForAtArea(..., false) is wrongly typed. HOT 1
- getDirectionTo can return undefined but typings only have DirectionConstant as a return value.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typed-screeps.