国际象棋的打字稿声明文件 [英] Typescript declaration file for chess.js
本文介绍了国际象棋的打字稿声明文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取打字稿,并为国际象棋.js库创建声明文件. https://github.com/jhlywa/chess.js .似乎我不了解如何制作一个.当我尝试使用import语句
I'm trying to pick up typescript and working on creating a declaration file for the chess.js lib https://github.com/jhlywa/chess.js. It seems I do not have the grasp of how to make one. When I try to import the lib using the import statement
import { Chess } from chess.js
它抱怨Module.js没有导出成员.
It complains that Module chess.js has no exported members.
到目前为止,这就是我的index.d.ts文件.
This is what I have so far I'm the index.d.ts file.
declare namespace ChessJSTypes {
type ChessType = 'p' | 'n' | 'b' | 'r' | 'q' | 'k';
type ChessColor = 'b' | 'w';
}
interface MoveOptions {
sloppy: boolean;
}
interface HistoryOptions {
verbose: boolean;
}
interface MovesOptions {
legal?: boolean;
square?: string;
verbose?: boolean;
}
interface PgnOptions {
sloppy?: boolean;
max_width?: number;
newline_char?: string;
}
interface IFlags {
NORMAL: string;
CAPTURE: string;
BIG_PAWN: string;
EP_CAPTURE: string;
PROMOTION: string;
KSIDE_CASTLE: string;
QSIDE_CASTLE: string;
}
interface Move {
to: string;
from: string;
san?: string;
flags?: string;
piece?: string;
color?: string;
captured?: string;
promotion?: string;
}
interface ValidationObject {
error: string;
valid: boolean;
error_number: number;
}
interface ChessPiece {
type: ChessJSTypes.ChessType;
color: ChessJSTypes.ChessColor;
}
declare class Chess {
readonly PAWN: string;
readonly KNIGHT: string;
readonly BISHOP: string;
readonly ROOK: string;
readonly QUEEN: string;
readonly KING: string;
readonly BLACK: string;
readonly WHITE: string;
readonly FLAGS: IFlags;
constructor(fen: string);
constructor();
board(): ChessPiece[][];
load(fen: string): boolean;
reset(): void;
moves(options?: MovesOptions): string[] | Move[];
in_check(): boolean;
in_checkmate(): boolean;
in_stalemate(): boolean;
in_draw(): boolean;
insufficient_material(): boolean;
in_threefold_repetition(): boolean;
game_over(): boolean;
validate_fen(fen: string): ValidationObject;
fen(): string;
pgn(option?: PgnOptions): string;
load_pgn(pgn: string, options?: PgnOptions): boolean;
header(args?: any): void;
header(): any;
ascii(): string;
turn(): string;
move(move: string | Move, options?: MoveOptions): Move;
undo(): Move;
clear(): void;
put(piece: ChessPiece, square: string): boolean;
get(square: string): ChessPiece;
remove(square: string): ChessPiece;
perft(depth: number): number;
square_color(square: string): string;
history(options: HistoryOptions): Move[];
history(): string[];
}
declare module 'chess.js' {
var Chess: Chess;
export = Chess;
}
推荐答案
您可以做的一件事是声明模块并在其中移动所有内容,而无需尝试在声明中导出任何内容:
One thing you could do is to declare the module and move everything inside, without trying to export anything within the declaration:
import * as Chess from 'chess.js';
declare module 'chess.js' {
class Chess {
// ...
}
}
这篇关于国际象棋的打字稿声明文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文