Screeps-Typescript-Declarations icon indicating copy to clipboard operation
Screeps-Typescript-Declarations copied to clipboard

Object for defining globals

Open dmarcuse opened this issue 7 years ago • 2 comments

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)

dmarcuse avatar Dec 06 '16 19:12 dmarcuse

It would likely be more helpful to store a type for global with an interface that promotes extensibility. Importantly, class types will cancel those from .d.ts files out under certain circumstances, so this must be done carefully. I recommend following the extensibility model put forth under #72 for classes, with the interface methodology allowing new information to be added without overwriting the existing ones. A similar model can be used for memory customization, with the added benefit that the user can further constrain the types by redeclaring the interface with a more precise interface later.

Dessix avatar Feb 06 '17 02:02 Dessix

global should not be typed by this project. It's unrelated to the Screeps code base, and will only make it more of a pain for users to integrate their own typings.

The global object that currently exists in Screeps is from Node. If you want it typed, you can add it's typings with typings install --save --global "[email protected]", and then extend it in your own code with:

declare namespace NodeJS {
  export interface Global {
     // whatever you want to add
  }
}

bryanbecker avatar May 15 '17 04:05 bryanbecker