Skip to content

Commit

Permalink
Merge pull request #15698 from brollin/isolated-declarations-chess-mo…
Browse files Browse the repository at this point in the history
…dule

Enable IsolatedDeclarations in chess module
  • Loading branch information
schlawg committed Jul 11, 2024
2 parents 4b1053a + 14525c4 commit 2439c38
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"lint-staged": "^15.2.2",
"onchange": "^7.1.0",
"prettier": "3.0.2",
"typescript": "^5.4.2"
"typescript": "^5.5.3"
},
"scripts": {
"format": "prettier --write --log-level warn .",
Expand Down
109 changes: 71 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/.build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"fast-glob": "^3.3.2",
"json5": "^2.2.3",
"tinycolor2": "^1.6.0",
"typescript": "^5.4.3"
"typescript": "^5.5.3"
},
"scripts": {
"dev": "tsc && node dist/main.js"
Expand Down
2 changes: 1 addition & 1 deletion ui/chess/src/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ export const charRole = (char: string) =>
Q: 'queen',
K: 'king',
})[char] as Role;
export const promo = (uci: Uci) => charRole(uci.slice(4, 5).toUpperCase() as RoleChar);
export const promo = (uci: Uci): Role => charRole(uci.slice(4, 5).toUpperCase() as RoleChar);
10 changes: 6 additions & 4 deletions ui/chess/src/sanWriter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Square } from 'chessops';

export type Board = { pieces: { [key: number]: string }; turn: boolean };
export type SanToUci = { [key: string]: Uci };

Expand All @@ -9,11 +11,11 @@ function decomposeUci(uci: string) {
return [uci.slice(0, 2), uci.slice(2, 4), uci.slice(4, 5)];
}

export function square(name: string) {
export function square(name: string): Square {
return name.charCodeAt(0) - 97 + (name.charCodeAt(1) - 49) * 8;
}

export function squareDist(a: number, b: number) {
export function squareDist(a: number, b: number): number {
const x1 = a & 7,
x2 = b & 7;
const y1 = a >> 3,
Expand All @@ -25,7 +27,7 @@ function isBlack(p: string) {
return p === p.toLowerCase();
}

export function readFen(fen: string) {
export function readFen(fen: string): Board {
const parts = fen.split(' '),
board: Board = {
pieces: {},
Expand Down Expand Up @@ -82,7 +84,7 @@ function slidingMovesTo(s: number, deltas: number[], board: Board): number[] {
return result;
}

export function sanOf(board: Board, uci: string) {
export function sanOf(board: Board, uci: string): San {
if (uci.includes('@')) return fixCrazySan(uci);

const move = decomposeUci(uci);
Expand Down
7 changes: 4 additions & 3 deletions ui/chess/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"compilerOptions": {
"outDir": "./dist",
"rootDir": "src",
"composite": true
"composite": true,
"isolatedDeclarations": true,
"isolatedModules": true
},
"references": [{ "path": "../common/tsconfig.json" }],
"isolatedModules": true
"references": [{ "path": "../common/tsconfig.json" }]
}

0 comments on commit 2439c38

Please sign in to comment.