Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with using Typescript with ravens-engine Phases #22

Open
mrhappyasthma opened this issue Oct 10, 2021 · 1 comment
Open

Issues with using Typescript with ravens-engine Phases #22

mrhappyasthma opened this issue Oct 10, 2021 · 1 comment

Comments

@mrhappyasthma
Copy link
Contributor

I'm in the process of trying to port the tutorial code (which I got working as js/jsx) to use Typescript (ts/tsx).

NOTE: I have little-to-no typescript knowledge.

It seems like there's some problem with the Phase class and how it relates to PhaseClass and AnyPhase.

I'm having two issues outlined below:

TicTacToeGame.childPhaseClasses = [LobbyPhase, GameInProgressPhase, GameEndedPhase];

error:

M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:692
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/TicTacToeGame.ts(30,36): error TS2322: Type 'typeof LobbyPhase' is not assignable to type 'PhaseClass<AnyPhase>'.
  Types of parameters 'parent' and 'parent' are incompatible.
    Type 'AnyPhase | null' is not assignable to type 'null'.
      Type 'AnyPhase' is not assignable to type 'null'.
src/TicTacToeGame.ts(30,48): error TS2322: Type 'typeof GameInProgressPhase' is not assignable to type 'PhaseClass<AnyPhase>'.
  Types of parameters 'parent' and 'parent' are incompatible.
    Type 'AnyPhase | null' is not assignable to type 'null'.
      Type 'AnyPhase' is not assignable to type 'null'.
src/TicTacToeGame.ts(30,69): error TS2322: Type 'typeof GameEndedPhase' is not assignable to type 'PhaseClass<AnyPhase>'.
  Types of parameters 'parent' and 'parent' are incompatible.
    Type 'AnyPhase | null' is not assignable to type 'null'.
      Type 'AnyPhase' is not assignable to type 'null'.

    at createTSError (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:692:12)
    at reportTSError (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:696:19)
    at getOutput (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:883:36)
    at Object.compile (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1185:30)
    at Module.m._compile (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  diagnosticText: "src/TicTacToeGame.ts(30,36): error TS2322: Type 'typeof LobbyPhase' is not assignable to type 'PhaseClass<AnyPhase>'.\r\n" +
    "  Types of parameters 'parent' and 'parent' are incompatible.\r\n" +
    "    Type 'AnyPhase | null' is not assignable to type 'null'.\r\n" +
    "      Type 'AnyPhase' is not assignable to type 'null'.\r\n" +
    "src/TicTacToeGame.ts(30,48): error TS2322: Type 'typeof GameInProgressPhase' is not assignable to type 'PhaseClass<AnyPhase>'.\r\n" +
    "  Types of parameters 'parent' and 'parent' are incompatible.\r\n" +
    "    Type 'AnyPhase | null' is not assignable to type 'null'.\r\n" +
    "      Type 'AnyPhase' is not assignable to type 'null'.\r\n" +
    "src/TicTacToeGame.ts(30,69): error TS2322: Type 'typeof GameEndedPhase' is not assignable to type 'PhaseClass<AnyPhase>'.\r\n" +
    "  Types of parameters 'parent' and 'parent' are incompatible.\r\n" +
    "    Type 'AnyPhase | null' is not assignable to type 'null'.\r\n" +
    "      Type 'AnyPhase' is not assignable to type 'null'.\r\n",
  diagnosticCodes: [ 2322, 2322, 2322 ]
}

and this line:

this.setChild(LobbyPhase)

which produces a similar error:

M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:692
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/TicTacToeGame.ts(26,19): error TS2345: Argument of type 'typeof LobbyPhase' is not assignable to parameter of type 'PhaseClass<null>'.
  Types of parameters 'parent' and 'parent' are incompatible.
    Type 'AnyPhase | null' is not assignable to type 'null'.
      Type 'AnyPhase' is not assignable to type 'null'.

    at createTSError (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:692:12)
    at reportTSError (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:696:19)
    at getOutput (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:883:36)
    at Object.compile (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1185:30)
    at Module.m._compile (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (M:\GitHub\TicTacToe-Ravens\node_modules\ts-node\src\index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  diagnosticText: "src/TicTacToeGame.ts(26,19): error TS2345: Argument of type 'typeof LobbyPhase' is not assignable to parameter of type 'PhaseClass<null>'.\r\n" +
    "  Types of parameters 'parent' and 'parent' are incompatible.\r\n" +
    "    Type 'AnyPhase | null' is not assignable to type 'null'.\r\n" +
    "      Type 'AnyPhase' is not assignable to type 'null'.\r\n",
  diagnosticCodes: [ 2345 ]
}

Am I missing something here? It seems like the problem is that the Phase classes that we implemented in the tutorial do not inherit from or implement AnyPhase or PhaseClass.

Is this a problem with how the tutorial code was written or a fundamental problem with the core code?

@Longwelwind
Copy link
Collaborator

I've tried to make Ravens Typescript-friendly, but I had a lot of trouble doing so due to the complexity of the generic types that I use. I've put Typescript support aside for the moment, as I'd rather work on something else than working on that.

I might add, in the future, some basic support. But being able to specify the state of a Phase, for example, and have this.state have proper typing seems to be harder than it looks.

I'll see what I can do. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants