From 885285734733b71c88dfb0da513988eb8678aa14 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 12 Sep 2016 20:25:56 +0200 Subject: fix compiler warnings --- lib/wallet/checkable.ts | 51 ++++++++++++++++++++++++++++++++++-------------- lib/wallet/cryptoApi.ts | 7 ++++--- lib/wallet/cryptoLib.ts | 9 +++++---- lib/wallet/db.ts | 13 ++++++------ lib/wallet/emscriptif.ts | 50 +++++++++++++++++++++++------------------------ lib/wallet/helpers.ts | 8 ++++---- lib/wallet/http.ts | 6 +++--- lib/wallet/types.ts | 2 +- 8 files changed, 84 insertions(+), 62 deletions(-) (limited to 'lib/wallet') diff --git a/lib/wallet/checkable.ts b/lib/wallet/checkable.ts index a35634e81..9fd816578 100644 --- a/lib/wallet/checkable.ts +++ b/lib/wallet/checkable.ts @@ -25,18 +25,39 @@ */ export namespace Checkable { - export function SchemaError(message) { + + type Path = (number|string)[]; + + interface SchemaErrorConstructor { + new (err: string): SchemaError; + } + + interface SchemaError { + name: string; + message: string; + } + + interface Prop { + propertyKey: any; + checker: any; + type: any; + elementChecker?: any; + elementProp?: any; + } + + export let SchemaError = (function SchemaError(message: string) { this.name = 'SchemaError'; this.message = message; this.stack = (new Error()).stack; - } + }) as any as SchemaErrorConstructor; + SchemaError.prototype = new Error; let chkSym = Symbol("checkable"); - function checkNumber(target, prop, path): any { + function checkNumber(target: any, prop: Prop, path: Path): any { if ((typeof target) !== "number") { throw new SchemaError(`expected number for ${path}`); } @@ -44,7 +65,7 @@ export namespace Checkable { } - function checkString(target, prop, path): any { + function checkString(target: any, prop: Prop, path: Path): any { if (typeof target !== "string") { throw new SchemaError(`expected string for ${path}, got ${typeof target} instead`); } @@ -52,7 +73,7 @@ export namespace Checkable { } - function checkAnyObject(target, prop, path): any { + function checkAnyObject(target: any, prop: Prop, path: Path): any { if (typeof target !== "object") { throw new SchemaError(`expected (any) object for ${path}, got ${typeof target} instead`); } @@ -60,12 +81,12 @@ export namespace Checkable { } - function checkAny(target, prop, path): any { + function checkAny(target: any, prop: Prop, path: Path): any { return target; } - function checkList(target, prop, path): any { + function checkList(target: any, prop: Prop, path: Path): any { if (!Array.isArray(target)) { throw new SchemaError(`array expected for ${path}, got ${typeof target} instead`); } @@ -77,7 +98,7 @@ export namespace Checkable { } - function checkOptional(target, prop, path): any { + function checkOptional(target: any, prop: Prop, path: Path): any { console.assert(prop.propertyKey); prop.elementChecker(target, prop.elementProp, @@ -86,7 +107,7 @@ export namespace Checkable { } - function checkValue(target, prop, path): any { + function checkValue(target: any, prop: Prop, path: Path): any { let type = prop.type; if (!type) { throw Error(`assertion failed (prop is ${JSON.stringify(prop)})`); @@ -123,8 +144,8 @@ export namespace Checkable { } - export function Class(target) { - target.checked = (v) => { + export function Class(target: any) { + target.checked = (v: any) => { return checkValue(v, { propertyKey: "(root)", type: target, @@ -135,7 +156,7 @@ export namespace Checkable { } - export function Value(type) { + export function Value(type: any) { if (!type) { throw Error("Type does not exist yet (wrong order of definitions?)"); } @@ -152,7 +173,7 @@ export namespace Checkable { } - export function List(type) { + export function List(type: any) { let stub = {}; type(stub, "(list-element)"); let elementProp = mkChk(stub).props[0]; @@ -174,7 +195,7 @@ export namespace Checkable { } - export function Optional(type) { + export function Optional(type: any) { let stub = {}; type(stub, "(optional-element)"); let elementProp = mkChk(stub).props[0]; @@ -230,7 +251,7 @@ export namespace Checkable { } - function mkChk(target) { + function mkChk(target: any) { let chk = target[chkSym]; if (!chk) { chk = {props: []}; diff --git a/lib/wallet/cryptoApi.ts b/lib/wallet/cryptoApi.ts index a0113b2ea..2a2a7d319 100644 --- a/lib/wallet/cryptoApi.ts +++ b/lib/wallet/cryptoApi.ts @@ -27,9 +27,10 @@ import {Denomination} from "./types"; import {Offer} from "./wallet"; import {CoinWithDenom} from "./wallet"; import {PayCoinInfo} from "./types"; +type RegistryEntry = {resolve: any; reject: any}; export class CryptoApi { private nextRpcId: number = 1; - private rpcRegistry = {}; + private rpcRegistry: {[n: number]: RegistryEntry} = {}; private cryptoWorker: Worker; @@ -52,14 +53,14 @@ export class CryptoApi { } - private registerRpcId(resolve, reject): number { + private registerRpcId(resolve: any, reject: any): number { let id = this.nextRpcId++; this.rpcRegistry[id] = {resolve, reject}; return id; } - private doRpc(methodName: string, ...args): Promise { + private doRpc(methodName: string, ...args: any[]): Promise { return new Promise((resolve, reject) => { let msg = { operation: methodName, diff --git a/lib/wallet/cryptoLib.ts b/lib/wallet/cryptoLib.ts index 1acbdaa16..1ca7b856f 100644 --- a/lib/wallet/cryptoLib.ts +++ b/lib/wallet/cryptoLib.ts @@ -28,6 +28,7 @@ import {Offer} from "./wallet"; import {CoinWithDenom} from "./wallet"; import {CoinPaySig} from "./types"; import {Denomination} from "./types"; +import {Amount} from "./emscriptif"; export function main(worker: Worker) { @@ -43,7 +44,7 @@ export function main(worker: Worker) { if (typeof msg.data.operation != "string") { console.error("RPC operation must be string"); } - let f = RpcFunctions[msg.data.operation]; + let f = (RpcFunctions as any)[msg.data.operation]; if (!f) { console.error(`unknown operation: '${msg.data.operation}'`); return; @@ -156,7 +157,7 @@ namespace RpcFunctions { } - export function rsaUnblind(sig, bk, pk): string { + export function rsaUnblind(sig: string, bk: string, pk: string): string { let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig), native.RsaBlindingKeySecret.fromCrock(bk), native.RsaPublicKey.fromCrock(pk)); @@ -170,11 +171,11 @@ namespace RpcFunctions { */ export function signDeposit(offer: Offer, cds: CoinWithDenom[]): PayCoinInfo { - let ret = []; + let ret: PayCoinInfo = []; let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency); let amountRemaining = new native.Amount(offer.contract.amount); for (let cd of cds) { - let coinSpend; + let coinSpend: Amount; if (amountRemaining.value == 0 && amountRemaining.fraction == 0) { break; diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts index 6cd25ee27..7fe635b9e 100644 --- a/lib/wallet/db.ts +++ b/lib/wallet/db.ts @@ -15,6 +15,7 @@ */ "use strict"; +import Dictionary = _.Dictionary; /** * Declarations and helpers for @@ -83,27 +84,27 @@ export function openTalerDb(): Promise { } -export function exportDb(db): Promise { +export function exportDb(db: IDBDatabase): Promise { let dump = { name: db.name, version: db.version, - stores: {} + stores: {} as Dictionary, }; return new Promise((resolve, reject) => { let tx = db.transaction(db.objectStoreNames); - tx.addEventListener("complete", (e) => { + tx.addEventListener("complete", () => { resolve(dump); }); for (let i = 0; i < db.objectStoreNames.length; i++) { let name = db.objectStoreNames[i]; - let storeDump = {}; + let storeDump = {} as Dictionary; dump.stores[name] = storeDump; let store = tx.objectStore(name) .openCursor() - .addEventListener("success", (e) => { - let cursor = e.target.result; + .addEventListener("success", (e: Event) => { + let cursor = (e.target as any).result; if (cursor) { storeDump[cursor.key] = cursor.value; cursor.continue(); diff --git a/lib/wallet/emscriptif.ts b/lib/wallet/emscriptif.ts index 8540d15d0..a12128666 100644 --- a/lib/wallet/emscriptif.ts +++ b/lib/wallet/emscriptif.ts @@ -36,11 +36,11 @@ const GNUNET_SYSERR = -1; let Module = EmscWrapper.Module; -let getEmsc: EmscWrapper.EmscFunGen = (...args) => Module.cwrap.apply(null, +let getEmsc: EmscWrapper.EmscFunGen = (...args: any[]) => Module.cwrap.apply(null, args); var emsc = { - free: (ptr) => Module._free(ptr), + free: (ptr: number) => Module._free(ptr), get_value: getEmsc('TALER_WR_get_value', 'number', ['number']), @@ -164,13 +164,12 @@ enum RandomQuality { abstract class ArenaObject { - private _nativePtr: number; + private _nativePtr: number | undefined = undefined; arena: Arena; abstract destroy(): void; constructor(arena?: Arena) { - this.nativePtr = null; if (!arena) { if (arenaStack.length == 0) { throw Error("No arena available") @@ -192,9 +191,9 @@ abstract class ArenaObject { } free() { - if (this.nativePtr !== undefined) { + if (this.nativePtr) { emsc.free(this.nativePtr); - this.nativePtr = undefined; + this._nativePtr = undefined; } } @@ -212,21 +211,22 @@ abstract class ArenaObject { this._nativePtr = n; } - set nativePtr(v) { + set nativePtr(v: number) { this.setNative(v); } get nativePtr() { return this.getNative(); } - } + interface Arena { put(obj: ArenaObject): void; destroy(): void; } + class DefaultArena implements Arena { heap: Array; @@ -234,7 +234,7 @@ class DefaultArena implements Arena { this.heap = []; } - put(obj) { + put(obj: ArenaObject) { this.heap.push(obj); } @@ -269,7 +269,7 @@ class SyncArena extends DefaultArena { super(); } - pub(obj) { + pub(obj: ArenaObject) { super.put(obj); if (!this.isScheduled) { this.schedule(); @@ -308,14 +308,12 @@ export class Amount extends ArenaObject { } destroy() { - if (this.nativePtr != 0) { - emsc.free(this.nativePtr); - } + super.free(); } static getZero(currency: string, a?: Arena): Amount { - let am = new Amount(null, a); + let am = new Amount(undefined, a); let r = emsc.amount_get_zero(currency, am.getNative()); if (r != GNUNET_OK) { throw Error("invalid currency"); @@ -442,7 +440,7 @@ abstract class PackedArenaObject extends ArenaObject { } alloc() { - if (this.nativePtr === null) { + if (!this.nativePtr) { this.nativePtr = emscAlloc.malloc(this.size()); } } @@ -466,7 +464,7 @@ abstract class PackedArenaObject extends ArenaObject { b = (b + 256) % 256; bytes.push("0".concat(b.toString(16)).slice(-2)); } - let lines = []; + let lines: string[] = []; for (let i = 0; i < bytes.length; i += 8) { lines.push(bytes.slice(i, i + 8).join(",")); } @@ -482,7 +480,7 @@ export class AmountNbo extends PackedArenaObject { toJson(): any { let a = new DefaultArena(); - let am = new Amount(null, a); + let am = new Amount(undefined, a); am.fromNbo(this); let json = am.toJson(); a.destroy(); @@ -508,7 +506,7 @@ export class EddsaPrivateKey extends PackedArenaObject { return obj; } - static fromCrock: (string) => EddsaPrivateKey; + static fromCrock: (s: string) => EddsaPrivateKey; } mixinStatic(EddsaPrivateKey, fromCrock); @@ -521,7 +519,7 @@ function fromCrock(s: string) { } -function mixin(obj, method, name?: string) { +function mixin(obj: any, method: any, name?: string) { if (!name) { name = method.name; } @@ -532,7 +530,7 @@ function mixin(obj, method, name?: string) { } -function mixinStatic(obj, method, name?: string) { +function mixinStatic(obj: any, method: any, name?: string) { if (!name) { name = method.name; } @@ -595,7 +593,7 @@ export class RsaBlindingKeySecret extends PackedArenaObject { return o; } - static fromCrock: (string) => RsaBlindingKeySecret; + static fromCrock: (s: string) => RsaBlindingKeySecret; } mixinStatic(RsaBlindingKeySecret, fromCrock); @@ -622,9 +620,9 @@ export class ByteArray extends PackedArenaObject { return this.allocatedSize; } - constructor(desiredSize: number, init: number, a?: Arena) { + constructor(desiredSize: number, init?: number, a?: Arena) { super(a); - if (init === undefined || init === null) { + if (init === undefined) { this.nativePtr = emscAlloc.malloc(desiredSize); } else { this.nativePtr = init; @@ -642,7 +640,7 @@ export class ByteArray extends PackedArenaObject { let hstr = emscAlloc.malloc(s.length + 1); Module.writeStringToMemory(s, hstr); let decodedLen = Math.floor((s.length * 5) / 8); - let ba = new ByteArray(decodedLen, null, a); + let ba = new ByteArray(decodedLen, undefined, a); let res = emsc.string_to_data(hstr, s.length, ba.nativePtr, decodedLen); emsc.free(hstr); if (res != GNUNET_OK) { @@ -899,11 +897,11 @@ interface Encodeable { encode(arena?: Arena): ByteArray; } -function makeEncode(encodeFn) { +function makeEncode(encodeFn: any) { function encode(arena?: Arena) { let ptr = emscAlloc.malloc(PTR_SIZE); let len = encodeFn(this.getNative(), ptr); - let res = new ByteArray(len, null, arena); + let res = new ByteArray(len, undefined, arena); res.setNative(Module.getValue(ptr, '*')); emsc.free(ptr); return res; diff --git a/lib/wallet/helpers.ts b/lib/wallet/helpers.ts index fd1650758..5d231fe64 100644 --- a/lib/wallet/helpers.ts +++ b/lib/wallet/helpers.ts @@ -24,7 +24,7 @@ import {AmountJson} from "./types"; -export function substituteFulfillmentUrl(url: string, vars) { +export function substituteFulfillmentUrl(url: string, vars: any) { url = url.replace("${H_contract}", vars.H_contract); url = url.replace("${$}", "$"); return url; @@ -42,7 +42,7 @@ export function amountToPretty(amount: AmountJson): string { * * See http://api.taler.net/wallet.html#general */ -export function canonicalizeBaseUrl(url) { +export function canonicalizeBaseUrl(url: string) { let x = new URI(url); if (!x.protocol()) { x.protocol("https"); @@ -54,10 +54,10 @@ export function canonicalizeBaseUrl(url) { } -export function parsePrettyAmount(pretty: string): AmountJson { +export function parsePrettyAmount(pretty: string): AmountJson|undefined { const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty); if (!res) { - return null; + return undefined; } return { value: parseInt(res[1], 10), diff --git a/lib/wallet/http.ts b/lib/wallet/http.ts index 60f388e4b..8f82ceaff 100644 --- a/lib/wallet/http.ts +++ b/lib/wallet/http.ts @@ -66,19 +66,19 @@ export class BrowserHttpLib { } - postJson(url: string|uri.URI, body) { + postJson(url: string|uri.URI, body: any) { return this.req("post", url, {req: JSON.stringify(body)}); } - postForm(url: string|uri.URI, form) { + postForm(url: string|uri.URI, form: any) { return this.req("post", url, {req: form}); } } export class RequestException { - constructor(detail) { + constructor(detail: any) { } } diff --git a/lib/wallet/types.ts b/lib/wallet/types.ts index 2434dca32..e8b7a1e39 100644 --- a/lib/wallet/types.ts +++ b/lib/wallet/types.ts @@ -392,5 +392,5 @@ export interface CheckRepurchaseResult { export interface Notifier { - notify(); + notify(): void; } -- cgit v1.2.3