GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

Add definition for `global` variable #24

Closed Dimava closed 5 months ago

Dimava commented 8 months ago
// lib
declare global {
  interface LuaGlobal {
    // empty. Use interface merging to extend.
  }
  const global: LuaGlobal
}

// usage
declare global {
  interface LuaGlobal {
    savedData: string
  }
}
global.savedData = 'foo'
GlassBricks commented 7 months ago

It's much simpler to declare global yourself (as already described in the docs) than to use interface merging:

declare const global: {
  savedData: string
}
// or
interface MyGlobal {
...
}
declare const global: MyGlobal