Skip to content

Commit ca52b01

Browse files
committed
export some types in the NPM
1 parent a310545 commit ca52b01

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dist/server.js",
4242
"dist/esm",
4343
"dist/cjs",
44+
"dist/types",
4445
"client",
4546
"core",
4647
"debug",

rollup.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ const external = [
2727
const plugins = [
2828
babel({ exclude: '**/node_modules/**' }),
2929
resolve({ browser: true, only: [/svelte/] }),
30-
tsPlugin({ typescript: ttypescript }),
30+
tsPlugin({
31+
typescript: ttypescript,
32+
tsconfigOverride: {
33+
compilerOptions: {
34+
declaration: true,
35+
},
36+
},
37+
useTsconfigDeclarationDir: true,
38+
}),
3139
svelte({ extensions: ['.svelte'] }),
3240
];
3341

src/core/game.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ import { Flow } from './flow';
1111
import { ActionPayload, GameConfig, Move, LongFormMove, State } from '../types';
1212
import * as logging from './logger';
1313

14+
type ProcessedGameConfig = GameConfig & {
15+
flow: object;
16+
moveNames: string[];
17+
processMove: Function;
18+
};
19+
20+
function IsProcessed(
21+
game: GameConfig | ProcessedGameConfig
22+
): game is ProcessedGameConfig {
23+
return game.processMove !== undefined;
24+
}
25+
1426
/**
1527
* Game
1628
*
@@ -27,10 +39,12 @@ import * as logging from './logger';
2739
* action.args contain any additional arguments as an
2840
* Array.
2941
*/
30-
export function Game(game: GameConfig) {
42+
export function Game(
43+
game: GameConfig | ProcessedGameConfig
44+
): ProcessedGameConfig {
3145
// The Game() function has already been called on this
3246
// config object, so just pass it through.
33-
if (game.processMove) {
47+
if (IsProcessed(game)) {
3448
return game;
3549
}
3650

@@ -60,7 +74,7 @@ export function Game(game: GameConfig) {
6074

6175
flow,
6276

63-
moveNames: flow.moveNames,
77+
moveNames: flow.moveNames as string[],
6478

6579
processMove: (state: State, action: ActionPayload.MakeMove) => {
6680
let moveFn = flow.getMove(state.ctx, action.type, action.playerID);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"module": "esnext",
55
"moduleResolution": "node",
66
"declaration": false,
7-
"outDir": "built-ts",
7+
"declarationDir": "./dist/types",
88
"strict": false,
99
"allowSyntheticDefaultImports": true,
1010
"esModuleInterop": true,

0 commit comments

Comments
 (0)