Skip to content

Commit 271aecd

Browse files
authored
fix: Fix client types & move BoardProps to React package (#752)
* refactor(packages): Expose BoardProps type via 'boardgame.io/react' BoardProps depends on some types from `@types/react`, which won’t be installed for TS users not using React, so exporting it from the top-level `'boardgame.io'` module causes errors for those users. * refactor(client): Structure debug types to output a .d.ts file This places the Svelte Debug component type definition in an index.ts alongside the index.js that re-exports the Svelte component. * Revert "refactor(client): Structure debug types to output a .d.ts file" This reverts commit e8f0735. * refactor(client): Add svelte types to tsconfig, typing `.svelte` files * refactor(packages): Convert debug package to TS * feat(types): Hoist ambient declaration in main types file * chore(deps): Make Svelte a dependency For TS users, Svelte needs to be installed so its ambient types can be used. * build(tsconfig): Remove `types` field Now the Svelte types are imported in `src/types.ts`, we don’t need to tell `tsc` about them in `tsconfig`.
1 parent 2108808 commit 271aecd

9 files changed

Lines changed: 16 additions & 31 deletions

File tree

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
"style-loader": "^0.18.2",
140140
"superagent": "^3.8.3",
141141
"supertest": "^3.1.0",
142-
"svelte": "^3.12.1",
143142
"svelte-icons": "^1.1.0",
144143
"tempy": "^0.5.0",
145144
"ts-jest": "^24.0.2",
@@ -161,6 +160,7 @@
161160
"redux": "^4.0.0",
162161
"shortid": "^2.2.14",
163162
"socket.io": "^2.1.1",
163+
"svelte": "^3.24.0",
164164
"ts-toolbelt": "^6.3.6",
165165
"uuid": "3.2.1"
166166
},
File renamed without changes.

packages/react.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* https://opensource.org/licenses/MIT.
77
*/
88

9-
import { Client } from '../src/client/react';
9+
import { Client, BoardProps } from '../src/client/react';
1010
import Lobby from '../src/lobby/react';
1111

12-
export { Client, Lobby };
12+
export { Client, BoardProps, Lobby };

rollup.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ export default [
6969
{
7070
input: subpackages.reduce((obj, name) => {
7171
obj[name] = `packages/${name}.ts`;
72-
73-
// The debug package can't be converted to TS
74-
// yet due to the svelte import.
75-
if (name == 'debug') {
76-
obj[name] = 'packages/debug.js';
77-
}
7872
return obj;
7973
}, {}),
8074
external,

src/client/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Transport } from './transport/transport';
1515
import { LocalTransport, Local } from './transport/local';
1616
import { SocketIOTransport, SocketIO } from './transport/socketio';
1717
import { update, sync, makeMove, gameEvent } from '../core/action-creators';
18-
import Debug from './debug';
18+
import Debug from './debug/Debug.svelte';
1919
import { error } from '../core/logger';
2020
import { LogEntry, State, SyncInfo } from '../types';
2121

src/client/client.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import * as Actions from '../core/action-types';
1717
import * as ActionCreators from '../core/action-creators';
1818
import { ProcessGameConfig } from '../core/game';
19-
import Debug from './debug';
19+
import Debug from './debug/Debug.svelte';
2020
import { CreateGameReducer } from '../core/reducer';
2121
import { InitializeGame } from '../core/initialize';
2222
import { Transport, TransportOpts } from './transport/transport';
@@ -35,16 +35,10 @@ import {
3535
type ClientAction = ActionShape.Reset | ActionShape.Sync | ActionShape.Update;
3636
type Action = CredentialedActionShape.Any | ClientAction;
3737

38-
// TODO: Replace these types with the full debug interface.
39-
// These types only specify the known interface used by a client instance.
40-
declare class DebugPanel {
41-
constructor(opts: { target: HTMLElement; props: { client: _ClientImpl } });
42-
$destroy: () => void;
43-
}
44-
type Debug = {
38+
interface DebugOpt {
4539
target?: HTMLElement;
46-
impl?: typeof DebugPanel;
47-
};
40+
impl?: typeof Debug;
41+
}
4842

4943
/**
5044
* createDispatchers
@@ -93,7 +87,7 @@ export const createPluginDispatchers = createDispatchers.bind(null, 'plugin');
9387

9488
export interface ClientOpts<G extends any = any> {
9589
game: Game<G>;
96-
debug?: Debug | boolean;
90+
debug?: DebugOpt | boolean;
9791
numPlayers?: number;
9892
multiplayer?: (opts: TransportOpts) => Transport;
9993
gameID?: string;
@@ -106,8 +100,8 @@ export interface ClientOpts<G extends any = any> {
106100
* Implementation of Client (see below).
107101
*/
108102
export class _ClientImpl<G extends any = any> {
109-
private debug?: Debug | boolean;
110-
private _debugPanel?: DebugPanel | null;
103+
private debug?: DebugOpt | boolean;
104+
private _debugPanel?: Debug | null;
111105
private gameStateOverride?: any;
112106
private initialState: State<G>;
113107
private multiplayer: (opts: TransportOpts) => Transport;
@@ -329,7 +323,7 @@ export class _ClientImpl<G extends any = any> {
329323
this.transport.connect();
330324
this._running = true;
331325

332-
let debugImpl: Debug['impl'] | null = null;
326+
let debugImpl: DebugOpt['impl'] | null = null;
333327

334328
if (process.env.NODE_ENV !== 'production') {
335329
debugImpl = Debug;

src/client/debug/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Object } from 'ts-toolbelt';
22
import Koa from 'koa';
33
import { Store as ReduxStore } from 'redux';
4+
import 'svelte';
45
import * as ActionCreators from './core/action-creators';
56
import { Flow } from './core/flow';
67
import { CreateGameReducer } from './core/reducer';
@@ -10,7 +11,6 @@ import { EventsAPI } from './plugins/plugin-events';
1011
import { RandomAPI } from './plugins/plugin-random';
1112

1213
export { StorageAPI };
13-
export { BoardProps } from './client/react';
1414

1515
export type AnyFn = (...args: any[]) => any;
1616

0 commit comments

Comments
 (0)