Giter Club home page Giter Club logo

screeps-typescript-declarations's Issues

Creep body part typings suggestion

With some uses of literal types, we can allow body part typings to accurately reflect their values while not affecting backward compatibility with those who are using the existing typings:

image

This can also be extended to other locations such as the Direction types.

"Map" definition conflicts with ES6 "Map" target

It seems that, since the definition for Map has no accessible constructor, we should be able to just rename it to something that doesn't conflict, so the Map type is usable for non-string dictionary keys?

helpers.ts LookAtResultMatrix interface

Think it should be declared as a string for named array, compiler was balking til I changed it.

interface LookAtResultMatrix {
    [coord: string]: LookAtResultMatrix|LookAtResult[]
}

Take over of the repo and npm package

I just had a move across the planet and didn't get your message until now. I will take over the repo and package if you don't want to maintain them anymore

Many types are 1-tuples where they should be arrays

Throughout the declarations there are many occurrences of 1-tuples where it should have been an array.

[string] is a 1-tuple containing 1 element of type string.

string[] is an array of string elements.

And what is even more confusing is that tuples are bugged in TypeScript, allowing to use more elements than defined: microsoft/TypeScript#6229

An example of this issue in the present declarations:

RoomPosition.findClosestByRange<T>(objects: [T|RoomPosition], opts?: {filter: any|string }): T;

Which should actually be:

RoomPosition.findClosestByRange<T>(objects: T[]|RoomPosition[], opts?: {filter: any|string }): T;

I will try to fix all of them and do a pull request.

nuker added to CONSTRUCTION_COST constant.ts

Needs to be added to end.

declare var CONSTRUCTION_COST: {
    spawn: number;
    extension: number;
    road: number;
    constructedWall: number;
    rampart: number;
    link: number;
    storage: number;
    tower: number;
    observer: number;
    powerSpawn: number;
    extractor: number;
    lab: number;
    terminal: number;
    container: number;
    nuker: number;
};

filter and algorithm should be made optional.

I added the question marks (?) to the opts object. This was causing my code to throw errors since I was only using filter and not specifying the algorithm (using the default).

    /**
     * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm.
     * @param type See Room.find
     * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm
     */
    findClosestByPath<T>(type: number, opts?: {
        filter?: any | string;
        algorithm?: string;
    }): T;
    /**
     * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm.
     * @param objects An array of room's objects or RoomPosition objects that the search should be executed against.
     * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm
     */
    findClosestByPath<T>(objects: [T | RoomPosition], opts?: {
        filter?: any | string;
        algorithm?: string;
    }): T;

Question - how to make ts-jest happy at test runtime?

Hello there!

I'm struggling with setting up unit tests that depend on Screeps types.

For example, when trying to extend Creeps like this:

Creep.prototype.someFunction = ...

My IDE is happy, the compiled code runs in game just fine, all types are resolved. But, when executing a unit test that imports the above code, it always fails with

ReferenceError: Creep is not defined

How to teach ts-jest to look at the right place and resolve Creep and other types located in node_modules/@types/screeps/index.d.ts ?

Thank you in advance!

assigning literal values to constants

I recently imported screeps.d.ts and noticed that there were a few issues related to literal values assigned to game constants. Previously they were declared like this:

declare const SOURCE_ENERGY_CAPACITY: number;

Now they are declared like this:

declare const SOURCE_ENERGY_CAPACITY: 3000;

This caused a lot of compiler errors, here is an example:

let score = SOURCE_ENERGY_CAPACITY;
if (WorldMap.roomTypeFromName(sourcePos.roomName) === ROOMTYPE_SOURCEKEEPER) {
    // TS2322: Type '4000' is not assignable to type '3000'
    score = SOURCE_ENERGY_KEEPER_CAPACITY;
}

I'm curious about the rationale for this specific way of declaring types and what situations that it would help. I'm also wondering if there is some setting that I can use to allow it to understand that I'm aiming for a number type here.

Allow typing of default memory objects

It seems that currently, you can't apply an interface to members of the built-in Memory objects (such as Memory.creeps) because they're defined in index.d.ts as any. I'd like to propose making a dummy interface for each of the four built-in Memory objects so that a player can then extend those interfaces in their own definition files.

For example, say I make my own interface for a room's memory:

interface MemRoom {
  name: string;
  type: string;
  threat: boolean;
}

If I try to apply it to Memory as follows:

interface Memory {
  rooms: {
    [name: string]: MemRoom;
  };
}

Then with the current typings I will get this error:

error TS2403: Subsequent variable declarations must have the same type.  Variable 'rooms' must be of type '{ [name: string]: any; }', but here has type '{ [name: string]: MemRoom; }'.

If however, there were already a "dummy" interface in the typings called MemRoom:

interface Memory {
    [name: string]: any;
    ...
    rooms: {
        [name: string]: MemRoom;
    };
    ...
}
interface MemRoom {
  [name: string]: any;
}
declare class Room {
  ...
    /**
     * A shorthand to Memory.rooms[room.name]. You can use it for quick access the room’s specific memory data object.
     */
    memory: MemRoom;
  ...
}

Then I could extend MemRoom to give specific types to any variables I want (as I tried to do above). This could be done for all four default Memory objects, and would allow users to type things that they want to store in memory - a huge advantage, I think, since Memory is the biggest source of errors for me these days!

If there is already a way to accomplish this that doesn't require modifying the current screeps declarations, please let me know as I'd be very curious!

Object for defining globals

In screeps, there's an object global which can be used to store values globally (i.e. for use from the console). It should be as simple as adding a declare var global:any; in the code, but I'm not sure where it should be put (hence an issue instead of a PR)

Problem with the Game arrays

Thanks for creating and keeping this updated.

I noticed issues compiling and I think I see the problem but I'm pretty new at this.
It's the declarations for Game.rooms/flags/creeps etc. Instead of just an array, shouldn't they be like this?

  creeps: {[creepName: string]: Creep};
  rooms: {[roomName: string]: Room};
  spawns: {[spawnName: string]: Spawn};
  structures: {[structureId: string]: Structure};

Missing extrends

It seems both StructureContainer and Spawn is missing the extends Structure in declaration.

I am very new to the game, so I might be overlooking something though. The error I'm getting is I cannot use them as RoomObject in i.e. moveTo

Source should be class?

I had problems using a variable of Source | Ressource, as instanceof only works for classes it seems, and I need to narrow the type for a function call to Creep.harvest. Should Source be a class, or is there another way to narrow the type?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.