【发布时间】:2017-09-14 21:03:15
【问题描述】:
希望为 DefinitiveTyped 创建一些声明文件(所以我想确保它们是最高质量的)。
我要使用的下一个库是https://github.com/oakmac/chessboardjs/。如果我像这样导入它,我实际上可以正常工作
// WHAT WORKS
import * as ChessBoard from "chessboardjs";
现在我可以通过调用来使用库
const board = ChessBoard('board1', 'start');
问题是我希望 import 语句是隐式的(ES6 风格),但不知道该怎么做
// WHAT I WOULD LIKE
import { ChessBoard } from "chessboardjs";
如果可能的话,我想要一些有关如何执行此操作的指导。由于我对打字稿和声明文件还很陌生,也许这个库不是为隐式导入而构建的
这是我目前在 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;
}
谢谢!!!
【问题讨论】:
-
嘿,只是想知道——你在这个库的类型上取得了进一步的进展吗?
-
我想我做到了。不过,我还没有把它推到确定类型。如果你也在做类似的事情,我可以同时与你分享
-
我正在做一些可以极大地受益于国际象棋和棋盘的打字的东西。您可以通过 gmail dot com 的 rikkigibson 与我联系。 (抱歉,没有看到任何其他传达联系信息的方式。)
-
Np。我会在几分钟内将它们发送到您的电子邮件中
标签: javascript angular typescript npm typescript-typings