From 8a9f6096ee913b05664c13cddee53957d06ee7a9 Mon Sep 17 00:00:00 2001 From: Valerie Date: Sat, 26 Jun 2021 13:07:11 -0400 Subject: [PATCH] no implicit any --- package.json | 2 ++ src/Game.ts | 4 ++-- src/TaskList.ts | 2 +- src/Time.ts | 2 +- src/multiplayer/mDNS.ts | 4 ++-- src/registries/Items.ts | 4 ++-- src/types.d.ts | 1 + src/ui/GiftPopup.ts | 2 +- src/ui/Menu.ts | 4 ++-- src/ui/PawnDetails.ts | 2 +- src/ui/Popup.ts | 6 +++--- src/ui/UI.ts | 2 +- src/ui/view/ActionsView.ts | 2 +- tsconfig.json | 3 ++- yarn.lock | 14 ++++++++++++++ 15 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 src/types.d.ts diff --git a/package.json b/package.json index f17d23f..cc0ad15 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "@types/bonjour": "^3.5.8", "@types/chai": "^4.2.19", "@types/faker": "^5.5.6", + "@types/fs-extra": "^9.0.11", "@types/mocha": "^8.2.2", "@types/uuid": "^8.3.0", + "@types/ws": "^7.4.5", "bonjour": "^3.5.0", "chai": "^4.3.4", "chalk": "^4.1.1", diff --git a/src/Game.ts b/src/Game.ts index 25c4472..9772cfd 100644 --- a/src/Game.ts +++ b/src/Game.ts @@ -9,7 +9,7 @@ import { render, Renderable, setTitle, start } from './ui/UI.js'; import { ready } from './multiplayer/mDNS.js'; import faker from 'faker'; -let game = null; +let game: Game = null; export class Game extends Frigid implements Tickable, Renderable { pawns: Pawn[] = []; @@ -47,7 +47,7 @@ export class Game extends Frigid implements Tickable, Renderable { }); } - advanceSelection(number) { + advanceSelection(number: number) { let index = this.pawns.indexOf(this.selected); this.selected = this.pawns[Math.min(Math.max(index + number, 0), this.pawns.length - 1)]; } diff --git a/src/TaskList.ts b/src/TaskList.ts index a080313..9c4625e 100644 --- a/src/TaskList.ts +++ b/src/TaskList.ts @@ -21,7 +21,7 @@ export class TaskList extends Serializable implements Renderable { this.tasks = [...this.tasks, task]; } - removeTask(task) { + removeTask(task: TaskState) { this.tasks = this.tasks.filter(v => v !== task); } diff --git a/src/Time.ts b/src/Time.ts index f3c9ee2..13c7d88 100644 --- a/src/Time.ts +++ b/src/Time.ts @@ -118,7 +118,7 @@ export default class Time extends Serializable implements Renderable { setTimeout(this.doTick.bind(this), 0); } - advanceTime(seconds) { + advanceTime(seconds: number) { this.minute += seconds / 60; this.normalize() } diff --git a/src/multiplayer/mDNS.ts b/src/multiplayer/mDNS.ts index 26e9bad..2aeeed6 100644 --- a/src/multiplayer/mDNS.ts +++ b/src/multiplayer/mDNS.ts @@ -29,7 +29,7 @@ export type GiftMessage = { export default network; -export async function ready(name) { +export async function ready(name: string) { const port = await getPort({port: getPort.makeRange(52300, 52399)}); mdns.publish({ type: 'dfi', @@ -39,7 +39,7 @@ export async function ready(name) { const wss = new WebSocket.Server({ port }); wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { - const {pawns: pawnJsons, from} = JSON.parse(message); + const {pawns: pawnJsons, from} = JSON.parse(message.toString()); const pawns = []; for(const pawnJson of pawnJsons) { const pawn: Pawn = Pawn.fromJson(pawnJson); diff --git a/src/registries/Items.ts b/src/registries/Items.ts index 03b3591..a901bbc 100644 --- a/src/registries/Items.ts +++ b/src/registries/Items.ts @@ -15,7 +15,7 @@ export class Item extends Serializable { id: ItemID = ''; props: Map = new Map(); - setName(name) { + setName(name: string) { this.name = name; this.register(false); return this; @@ -35,7 +35,7 @@ export class Item extends Serializable { } setProperty(prop: ItemProperty, value: any) { - this.props[prop.name] = value; + this.props.set(prop.name, value); return this; } diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..b037197 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1 @@ +declare module "neo-blessed"; \ No newline at end of file diff --git a/src/ui/GiftPopup.ts b/src/ui/GiftPopup.ts index 749a64f..53e7663 100644 --- a/src/ui/GiftPopup.ts +++ b/src/ui/GiftPopup.ts @@ -25,7 +25,7 @@ export class GiftPopup { tags: true, ...boxStyle(), }); - this.box.on('keypress', (evt, key) => { + this.box.on('keypress', (evt: {}, key: {full: string}) => { if(key.full === 'enter') { this.send(); } if(key.full === 'escape' || key.full === 'enter') { diff --git a/src/ui/Menu.ts b/src/ui/Menu.ts index 41aea90..4290f2c 100644 --- a/src/ui/Menu.ts +++ b/src/ui/Menu.ts @@ -13,7 +13,7 @@ import { View } from './View.js'; import { ActionsView } from './view/ActionsView.js'; import { tasks } from '@tasks'; -const clamp = (min, max, value) => Math.min(Math.max(value, min), max); +const clamp = (min: number, max: number, value: number) => Math.min(Math.max(value, min), max); // TODO move KeypressAcceptor to ui something idk export interface KeypressAcceptor { @@ -46,7 +46,7 @@ export class Menu implements Renderable { } constructor() { - panels.right.on('keypress', (evt, key) => { + panels.right.on('keypress', (evt: {}, key: {full: string}) => { if (key.full === 'left') { this.regressView(); diff --git a/src/ui/PawnDetails.ts b/src/ui/PawnDetails.ts index 2699717..971db0a 100644 --- a/src/ui/PawnDetails.ts +++ b/src/ui/PawnDetails.ts @@ -21,7 +21,7 @@ export class PawnDetails { tags: true, ...boxStyle(), }); - this.box.on('keypress', (evt, key) => { + this.box.on('keypress', (evt: {}, key: {full: string}) => { if(key.full === 'escape' || key.full === 'enter') { Game.current.clock.start(); panels.screen.remove(this.box); diff --git a/src/ui/Popup.ts b/src/ui/Popup.ts index e01ab72..e64534e 100644 --- a/src/ui/Popup.ts +++ b/src/ui/Popup.ts @@ -7,11 +7,11 @@ import { panels } from './UI.js'; export class Popup { box; - static show(content) { + static show(content: string) { new Popup(content) } - private constructor(content) { + private constructor(content: string) { this.box = blessed.box({ top: 'center', left: 'center', @@ -21,7 +21,7 @@ export class Popup { tags: true, ...boxStyle(), }); - this.box.on('keypress', (evt, key) => { + this.box.on('keypress', (evt: {}, key: {full: string}) => { if(key.full === 'escape' || key.full === 'enter') { Game.current.clock.start(); panels.screen.remove(this.box); diff --git a/src/ui/UI.ts b/src/ui/UI.ts index 32a028c..4dbf920 100644 --- a/src/ui/UI.ts +++ b/src/ui/UI.ts @@ -99,7 +99,7 @@ export function start() { process.stdout.write(ansi.cursor.hide); - screen.key(['C-c'], function(ch, key) { + screen.key(['C-c'], function() { process.stdout.write(ansi.cursor.show); setTimeout(_ => { process.exit(0); diff --git a/src/ui/view/ActionsView.ts b/src/ui/view/ActionsView.ts index b53385d..1876846 100644 --- a/src/ui/view/ActionsView.ts +++ b/src/ui/view/ActionsView.ts @@ -12,7 +12,7 @@ export class ActionsView extends View { this.name = 'Actions'; } - keypress(key) { + keypress(key: {full: string}) { if(key.full === 'up') { this.actionIdx --; } else if (key.full === 'down') { diff --git a/tsconfig.json b/tsconfig.json index 4977fa7..bcb37a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,8 @@ "@tasks": ["./src/registries/Tasks"], "@items": ["./src/registries/Items"], "@game": ["./src/Game"] - } + }, + "noImplicitAny": true }, "include": [ "src/**/*.ts", diff --git a/yarn.lock b/yarn.lock index b45ded0..532cbb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -35,6 +35,13 @@ version "5.5.6" resolved "https://registry.yarnpkg.com/@types/faker/-/faker-5.5.6.tgz#039b700a9d8ad9150ecc842bf5e717e2027b6f75" +"@types/fs-extra@^9.0.11": + version "9.0.11" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.11.tgz#8cc99e103499eab9f347dbc6ca4e99fb8d2c2b87" + integrity sha512-mZsifGG4QeQ7hlkhO56u7zt/ycBgGxSVsFI/6lGTU34VtwkiqrrSDgw0+ygs8kFGWcXnFQWMrzF2h7TtDFNixA== + dependencies: + "@types/node" "*" + "@types/minimatch@^3.0.3", "@types/minimatch@^3.0.4": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21" @@ -53,6 +60,13 @@ version "8.3.0" resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f" +"@types/ws@^7.4.5": + version "7.4.5" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.5.tgz#8ff0f7efcd8fea19f51f9dd66cb8b498d172a752" + integrity sha512-8mbDgtc8xpxDDem5Gwj76stBDJX35KQ3YBoayxlqUQcL5BZUthiqP/VQ4PQnLHqM4PmlbyO74t98eJpURO+gPA== + dependencies: + "@types/node" "*" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"