In der Hoffnung, ein paar Deklarationsdateien für DefinitelyTyped zu erstellen (also möchte ich sicherstellen, dass sie Top-Qualität sind).Typescript Deklarationsdatei für schachbrettjs (impliziter Import)
Die nächste lib, die ich nehme, ist https://github.com/oakmac/chessboardjs/. Ich habe es tatsächlich funktioniert, wenn ich es wie so
// WHAT WORKS
import * as ChessBoard from "chessboardjs";
importieren und jetzt kann ich die lib verwenden, indem
const board = ChessBoard('board1', 'start');
Aufruf
Das Problem, das ich die Import-Anweisung implizit sein wollen ist (ES6 Stil) und nicht sicher, wie man das macht,
Ich würde gerne einige Anleitung, wie man dies tun, wenn möglich. Da ich immer noch bin neu Typoskript und Deklarationsdateien, vielleicht auch nur die lib für implizite Importe nicht
gebaut ist, was ich in den index.d.ts
declare namespace ChessBoardJS {
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?: ChessBoardJS.Types.OrientationType;
showErrors?: boolean | string | Function;
moveSpeed?: number | ChessBoardJS.Types.SpeedType;
snapSpeed?: number | ChessBoardJS.Types.SpeedType;
trashSpeed?: number | ChessBoardJS.Types.SpeedType;
dropOffBoard?: ChessBoardJS.Types.DropOffBoardType;
appearSpeed?: number | ChessBoardJS.Types.SpeedType;
snapbackSpeed?: number | ChessBoardJS.Types.SpeedType;
position?: ChessBoardJS.Types.PositionType | string | object;
}
}
declare namespace ChessBoardJS.Types {
type PositionType = 'start';
type PositionFenType = 'fen';
type SpeedType = 'slow' | 'fast';
type OrientationFlipType = 'flip';
type OrientationType = 'white' | 'black';
type DropOffBoardType = 'snapback' | 'trash';
}
interface ChessBoardInstance {
clear(useAnimation?: boolean): void;
destroy(): void;
fen(): string;
flip(): void;
move(...args: string[]): object; // *FIND RETURN*
position(newPosition: object | string | ChessBoardJS.Types.PositionType, useAnimation?: boolean): void
position(fen?: ChessBoardJS.Types.PositionFenType): string | object;
orientation(side?: ChessBoardJS.Types.OrientationType | ChessBoardJS.Types.OrientationFlipType): string;
resize(): void;
start(useAnimation?: boolean): void;
}
interface ChessBoardFactory {
(containerElOrId: any, config: ChessBoardJS.BoardConfig): ChessBoardInstance
fenToObj(fen: string): any;
objToFen(obj: any): any;
}
declare var ChessBoard: ChessBoardFactory;
declare module "chessboardjs" {
export = ChessBoard;
}
Thank Datei so weit haben Sie!!!
Hey, nur wundernd-- hast du irgendwelche Fortschritte bei den Typings für diese Bibliothek gemacht? –
Ich denke, ich habe es getan. Ich habe es allerdings noch nicht auf den Punkt gebracht. Ich kann es in der Zwischenzeit mit dir teilen, wenn du auch an etwas ähnlichem arbeitest –
Ich arbeite an etwas, das stark von den Typisierungen für Schach und Schachbrett profitieren würde. Sie können mich unter rikkigibson bei gmail dot com erreichen. (Sorry, habe keine anderen Möglichkeiten gesehen, Kontaktinformationen zu übermitteln.) –