Add types for sudokus (#36800)

This commit is contained in:
Florian Keller 2019-07-10 23:17:52 +02:00 committed by Armando Aguirre
parent cd095172b8
commit dfa2e41ed3
4 changed files with 62 additions and 0 deletions

17
types/sudokus/index.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
// Type definitions for sudokus 1.0
// Project: https://github.com/Moeriki/node-sudokus#readme
// Definitions by: Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type ProgressFn = (state: Cell[][]) => void;
export interface Cell {
fixed: boolean;
value: number;
}
export interface Options {
onProgress?: ProgressFn;
}
export function solve(data: number[][], options?: Options): number[][];

View File

@ -0,0 +1,21 @@
import { solve, ProgressFn, Cell } from 'sudokus';
const onProgress: ProgressFn = (cell: Cell[][]) => {
cell[0][0].fixed;
cell[0][0].value;
};
solve(
[
[0, 0, 0, 2, 9, 0, 1, 0, 0],
[6, 0, 0, 5, 0, 1, 0, 7, 0],
[0, 0, 0, 0, 0, 0, 0, 3, 4],
[0, 0, 0, 0, 0, 0, 9, 4, 0],
[4, 5, 0, 3, 0, 0, 0, 6, 2],
[2, 0, 9, 0, 0, 4, 3, 1, 0],
[0, 2, 0, 0, 0, 0, 4, 9, 0],
[0, 0, 6, 0, 0, 8, 0, 0, 0],
[0, 4, 3, 0, 2, 0, 0, 8, 7],
],
{ onProgress }
);

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sudokus-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }