From 90cc97cd3d6587d24ba9b68dd944b47ff4ea952f Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 9 Feb 2018 21:55:09 +0100 Subject: [PATCH] Fix errors in source code --- types/chessboardjs/chessboardjs-tests.ts | 34 ++--- types/chessboardjs/index.d.ts | 153 +++++++++++------------ 2 files changed, 90 insertions(+), 97 deletions(-) diff --git a/types/chessboardjs/chessboardjs-tests.ts b/types/chessboardjs/chessboardjs-tests.ts index b2750b0473..37c797037c 100644 --- a/types/chessboardjs/chessboardjs-tests.ts +++ b/types/chessboardjs/chessboardjs-tests.ts @@ -5,36 +5,36 @@ import chessboardjs = require('chessboardjs'); */ // empty position -var board = chessboardjs.ChessBoard('board'); +let board = chessboardjs.ChessBoard('board'); // Start position -var board = chessboardjs.ChessBoard('board', 'start'); +board = chessboardjs.ChessBoard('board', 'start'); // FEN string -var ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R'; -var board = chessboardjs.ChessBoard('board', ruyLopez); +const ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R'; +board = chessboardjs.ChessBoard('board', ruyLopez); // Position Object -var position: chessboardjs.BoardPositionType = { +let position: chessboardjs.BoardPositionType = { d6: chessboardjs.Piece.bK, d4: chessboardjs.Piece.wP, e4: chessboardjs.Piece.wK }; -var board = chessboardjs.ChessBoard('board', position); +board = chessboardjs.ChessBoard('board', position); // Multiple boards -var config1: chessboardjs.BoardConfig = { +const config1: chessboardjs.BoardConfig = { position: 'start', showNotation: false }; -var board1 = chessboardjs.ChessBoard('board1', config1); +const board1 = chessboardjs.ChessBoard('board1', config1); -var board2 = chessboardjs.ChessBoard('board2', { +const board2 = chessboardjs.ChessBoard('board2', { position: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R', showNotation: false }); -var board3 = chessboardjs.ChessBoard('board3', { +const board3 = chessboardjs.ChessBoard('board3', { position: 'r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1', showNotation: false }); @@ -44,14 +44,14 @@ var board3 = chessboardjs.ChessBoard('board3', { */ // Get Position -var cfg: chessboardjs.BoardConfig = { +const cfg: chessboardjs.BoardConfig = { draggable: true, position: 'start' }; -var board = chessboardjs.ChessBoard('board', cfg); -var pos: chessboardjs.BoardPositionType = board.position(); +board = chessboardjs.ChessBoard('board', cfg); +const pos: chessboardjs.BoardPositionType = board.position(); -var posFEN: string = board.position('fen'); +const posFEN: string = board.position('fen'); // Set position @@ -64,7 +64,7 @@ board.position(ruyLopez, true); // instantly board.position(ruyLopez, false); -var position: chessboardjs.BoardPositionType = { +position = { a4: chessboardjs.Piece.bK, c4: chessboardjs.Piece.wK, a7: chessboardjs.Piece.wR @@ -79,7 +79,7 @@ board.start(); board.move('e2-e4'); // Orientation -var oritentation = board.orientation(); +const oritentation = board.orientation(); // change orientation board.orientation('black'); @@ -89,4 +89,4 @@ board.orientation('black'); board.resize(); // Destroy -board.destroy(); \ No newline at end of file +board.destroy(); diff --git a/types/chessboardjs/index.d.ts b/types/chessboardjs/index.d.ts index 4f63d6f471..f6228f748e 100644 --- a/types/chessboardjs/index.d.ts +++ b/types/chessboardjs/index.d.ts @@ -5,85 +5,78 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 -declare namespace chessboardjs { - - enum Square { - a8 = 'a8', b8 = 'b8', c8 = 'c8', d8 = 'd8', e8 = 'e8', f8 = 'f8', g8 = 'g7', h8 = 'h8', - a7 = 'a7', b7 = 'b7', c7 = 'c7', d7 = 'd7', e7 = 'e7', f7 = 'f7', g7 = 'g7', h7 = 'h7', - a6 = 'a6', b6 = 'b6', c6 = 'c6', d6 = 'd6', e6 = 'e6', f6 = 'f6', g6 = 'g7', h6 = 'h6', - a5 = 'a5', b5 = 'b5', c5 = 'c5', d5 = 'd5', e5 = 'e5', f5 = 'f5', g5 = 'g7', h5 = 'h5', - a4 = 'a4', b4 = 'b4', c4 = 'c4', d4 = 'd4', e4 = 'e4', f4 = 'f4', g4 = 'g7', h4 = 'h4', - a3 = 'a3', b3 = 'b3', c3 = 'c3', d3 = 'd3', e3 = 'e3', f3 = 'f3', g3 = 'g7', h3 = 'h3', - a2 = 'a2', b2 = 'b2', c2 = 'c2', d2 = 'd2', e2 = 'e2', f2 = 'f2', g2 = 'g7', h2 = 'h2', - a1 = 'a1', b1 = 'b1', c1 = 'c1', d1 = 'd1', e1 = 'e1', f1 = 'f1', g1 = 'g7', h1 = 'h1', - } - - enum Piece { - bK = 'bK', bQ = 'bQ', bR = 'bR', bN = 'bN', bB = 'bB', bP = 'bP', - wK = 'wK', wQ = 'wQ', wR = 'wR', wN = 'wN', wB = 'wB', wP = 'wP' - } - - type BoardPositionType = { - [P in Square]?: Piece; - } - - type PositionType = 'start' | string | BoardPositionType; - type PositionFenType = 'fen'; - type SpeedType = 'slow' | 'fast'; - type OrientationFlipType = 'flip'; - type OrientationType = 'white' | 'black'; - type DropOffBoardType = 'snapback' | 'trash'; - - export interface BoardConfig { - onDrop?: Function; - draggable?: boolean; - onChange?: Function; - onMoveEnd?: Function; - onSnapEnd?: Function; - sparePieces?: boolean; - onDragMove?: Function; - showNotation?: boolean; - onDragStart?: Function; - onSnapbackEnd?: Function; - onMouseoutSquare?: Function; - onMouseoverSquare?: Function; - pieceTheme?: string | Function; - orientation?: OrientationType; - showErrors?: boolean | string | Function; - moveSpeed?: number | SpeedType; - snapSpeed?: number | SpeedType; - trashSpeed?: number | SpeedType; - dropOffBoard?: DropOffBoardType; - appearSpeed?: number | SpeedType; - snapbackSpeed?: number | SpeedType; - position?: PositionType; - } - - interface ChessBoardInstance { - clear(useAnimation?: boolean): void; - destroy(): void; - fen(): string; - flip(): void; - move(...args: string[]): BoardPositionType; - position(): BoardPositionType; - position(fen: PositionFenType): string; - position(newPosition: PositionType, useAnimation?: boolean): void - orientation(side?: OrientationType | OrientationFlipType): string; - resize(): void; - start(useAnimation?: boolean): void; - } - - interface ChessBoardFactory { - (containerElOrId: any, config?: BoardConfig): ChessBoardInstance - (containerElOrId: any, position: string): ChessBoardInstance - (containerElOrId: any, position: BoardPositionType): ChessBoardInstance - (containerElOrId: any): ChessBoardInstance - fenToObj(fen: string): boolean | BoardPositionType; - objToFen(obj: BoardPositionType): boolean | string; - } - - export var ChessBoard: ChessBoardFactory; +export enum Square { + a8 = 'a8', b8 = 'b8', c8 = 'c8', d8 = 'd8', e8 = 'e8', f8 = 'f8', g8 = 'g7', h8 = 'h8', + a7 = 'a7', b7 = 'b7', c7 = 'c7', d7 = 'd7', e7 = 'e7', f7 = 'f7', g7 = 'g7', h7 = 'h7', + a6 = 'a6', b6 = 'b6', c6 = 'c6', d6 = 'd6', e6 = 'e6', f6 = 'f6', g6 = 'g7', h6 = 'h6', + a5 = 'a5', b5 = 'b5', c5 = 'c5', d5 = 'd5', e5 = 'e5', f5 = 'f5', g5 = 'g7', h5 = 'h5', + a4 = 'a4', b4 = 'b4', c4 = 'c4', d4 = 'd4', e4 = 'e4', f4 = 'f4', g4 = 'g7', h4 = 'h4', + a3 = 'a3', b3 = 'b3', c3 = 'c3', d3 = 'd3', e3 = 'e3', f3 = 'f3', g3 = 'g7', h3 = 'h3', + a2 = 'a2', b2 = 'b2', c2 = 'c2', d2 = 'd2', e2 = 'e2', f2 = 'f2', g2 = 'g7', h2 = 'h2', + a1 = 'a1', b1 = 'b1', c1 = 'c1', d1 = 'd1', e1 = 'e1', f1 = 'f1', g1 = 'g7', h1 = 'h1', } -export = chessboardjs; -export as namespace chessboardjs; +export enum Piece { + bK = 'bK', bQ = 'bQ', bR = 'bR', bN = 'bN', bB = 'bB', bP = 'bP', + wK = 'wK', wQ = 'wQ', wR = 'wR', wN = 'wN', wB = 'wB', wP = 'wP' +} + +export type BoardPositionType = { + [P in Square]?: Piece; +}; + +export type PositionType = 'start' | string | BoardPositionType; +export type PositionFenType = 'fen'; +export type SpeedType = 'slow' | 'fast'; +export type OrientationFlipType = 'flip'; +export type OrientationType = 'white' | 'black'; +export type DropOffBoardType = 'snapback' | 'trash'; +export type Callback = () => void; + +export interface BoardConfig { + onDrop?: Callback; + draggable?: boolean; + onChange?: Callback; + onMoveEnd?: Callback; + onSnapEnd?: Callback; + sparePieces?: boolean; + onDragMove?: Callback; + showNotation?: boolean; + onDragStart?: Callback; + onSnapbackEnd?: Callback; + onMouseoutSquare?: Callback; + onMouseoverSquare?: Callback; + pieceTheme?: string | Callback; + orientation?: OrientationType; + showErrors?: boolean | string | Callback; + moveSpeed?: number | SpeedType; + snapSpeed?: number | SpeedType; + trashSpeed?: number | SpeedType; + dropOffBoard?: DropOffBoardType; + appearSpeed?: number | SpeedType; + snapbackSpeed?: number | SpeedType; + position?: PositionType; +} + +export interface ChessBoardInstance { + clear(useAnimation?: boolean): void; + destroy(): void; + fen(): string; + flip(): void; + move(...args: string[]): BoardPositionType; + position(): BoardPositionType; + position(fen: PositionFenType): string; + position(newPosition: PositionType, useAnimation?: boolean): void; + orientation(side?: OrientationType | OrientationFlipType): string; + resize(): void; + start(useAnimation?: boolean): void; +} + +export interface ChessBoardFactory { + (containerElOrId: any, config?: BoardConfig): ChessBoardInstance; + (containerElOrId: any, position: string | BoardPositionType): ChessBoardInstance; + fenToObj(fen: string): boolean | BoardPositionType; + objToFen(obj: BoardPositionType): boolean | string; +} + +export const ChessBoard: ChessBoardFactory;