ARTICLE AD BOX
I have the following file to declare a global variable
globals.d.ts
import { Game } from './Game'; declare const game: Game; export {};However when I call the variable in a file I get the warning
Card.ts
class Card { ... draw() { // Cannot find name `game` game.hoverContext = { id: this.id, type: 'card', }; } }How am I meant to detect it in my TypeScript app? Is there a tsconfig property I should be adjusting?
124k31 gold badges280 silver badges489 bronze badges
1,4961 gold badge25 silver badges46 bronze badges
3
UPDATE: Based on feedback from @VLAZ, I updated my main.ts to export my game instance and import that to my other modules. This works and is more concise than my previous attempt
main.ts
import Game from 'Game'; export const game : Game = new Game()and now in each of my modules, I'm declaring game
module.ts
import { game } from '../main'; class Card { ... draw() { -- no errors since it has type declaration in main.ts -- game.hoverContext = { id: this.id, type: 'card', }; } } }1,4961 gold badge25 silver badges46 bronze badges
2 Comments
Explore related questions
See similar questions with these tags.

