fix problems found by newer TypeScript compiler

This commit is contained in:
Florian Dold 2017-12-10 23:02:00 +01:00
parent 0469abd4a9
commit 3c882c44b5
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
12 changed files with 66 additions and 51 deletions

View File

@ -218,7 +218,7 @@ export class CryptoApi {
...args: any[]): Promise<T> {
const start = timer.performanceNow();
const p = new Promise((resolve, reject) => {
const p: Promise<T> = new Promise<T>((resolve, reject) => {
const rpcId = this.nextRpcId++;
const workItem: WorkItem = {operation, args, resolve, reject, rpcId};

View File

@ -127,9 +127,15 @@ export interface QueryStream<T> {
filter(f: (x: T) => boolean): QueryStream<T>;
/**
* Reduce the stream, resulting in a single value.
* Fold the stream, resulting in a single value.
*/
reduce<S>(f: (v: T, acc?: S) => S, start?: S): Promise<S>;
fold<S>(f: (v: T, acc: S) => S, start: S): Promise<S>;
/**
* Execute a function for every value of the stream, for the
* side-effects of the function.
*/
forEach(f: (v: T) => void): Promise<void>;
/**
* Map each element of the stream using a function, resulting in another
@ -324,7 +330,7 @@ abstract class QueryStreamBase<T> implements QueryStream<T> {
.then(() => promise);
}
reduce<A>(f: (x: any, acc?: A) => A, init?: A): Promise<any> {
fold<A>(f: (x: T, acc: A) => A, init: A): Promise<A> {
const {resolve, promise} = openPromise();
let acc = init;
@ -341,6 +347,22 @@ abstract class QueryStreamBase<T> implements QueryStream<T> {
.then(() => promise);
}
forEach(f: (x: T) => void): Promise<void> {
const {resolve, promise} = openPromise();
this.subscribe((isDone, value) => {
if (isDone) {
resolve();
return;
}
f(value);
});
return Promise.resolve()
.then(() => this.root.finish())
.then(() => promise);
}
run(): Promise<void> {
const {resolve, promise} = openPromise();
@ -699,7 +721,7 @@ export class QueryRoot {
* If the mutation function throws AbortTransaction, the whole transaction will be aborted.
* If the mutation function returns undefined or null, no modification will be made.
*/
mutate<T>(store: Store<T>, key: any, f: (v: T|undefined) => T|undefined): QueryRoot {
mutate<T>(store: Store<T>, key: any, f: (v: T) => T|undefined): QueryRoot {
this.checkFinished();
const doPut = (tx: IDBTransaction) => {
const req = tx.objectStore(store.name).openCursor(IDBKeyRange.only(key));

View File

@ -730,34 +730,34 @@ export class Wallet {
this.q()
.iter(Stores.reserves)
.reduce((reserve) => {
.forEach((reserve) => {
console.log("resuming reserve", reserve.reserve_pub);
this.processReserve(reserve);
});
this.q()
.iter(Stores.precoins)
.reduce((preCoin) => {
.forEach((preCoin) => {
console.log("resuming precoin");
this.processPreCoin(preCoin);
});
this.q()
.iter(Stores.refresh)
.reduce((r: RefreshSessionRecord) => {
.forEach((r: RefreshSessionRecord) => {
this.continueRefreshSession(r);
});
this.q()
.iter(Stores.coinsReturns)
.reduce((r: CoinsReturnRecord) => {
.forEach((r: CoinsReturnRecord) => {
this.depositReturnedCoins(r);
});
// FIXME: optimize via index
this.q()
.iter(Stores.coins)
.reduce((c: CoinRecord) => {
.forEach((c: CoinRecord) => {
if (c.status === CoinStatus.Dirty) {
console.log("resuming pending refresh for coin", c);
this.refresh(c.coinPub);
@ -1536,7 +1536,6 @@ export class Wallet {
);
let allValid = false;
let currentPossibleDenoms = possibleDenoms;
let selectedDenoms: DenominationRecord[];
@ -1561,7 +1560,6 @@ export class Wallet {
nextPossibleDenoms.push(denom);
}
}
currentPossibleDenoms = nextPossibleDenoms;
} while (selectedDenoms.length > 0 && !allValid);
return selectedDenoms;
@ -1709,7 +1707,7 @@ export class Wallet {
.iterIndex(Stores.coins.exchangeBaseUrlIndex, exchangeInfo.baseUrl)
.indexJoinLeft(Stores.denominations.exchangeBaseUrlIndex,
(e) => e.exchangeBaseUrl)
.reduce((cd: JoinLeftResult<CoinRecord, DenominationRecord>,
.fold((cd: JoinLeftResult<CoinRecord, DenominationRecord>,
suspendedCoins: CoinRecord[]) => {
if ((!cd.right) || (!cd.right.isOffered)) {
return Array.prototype.concat(suspendedCoins, [cd.left]);
@ -1718,7 +1716,7 @@ export class Wallet {
}, []));
const q = this.q();
resultSuspendedCoins.map((c) => {
resultSuspendedCoins.map((c: CoinRecord) => {
console.log("suspending coin", c);
c.suspended = true;
q.put(Stores.coins, c);
@ -1851,7 +1849,7 @@ export class Wallet {
const existingDenoms: {[denomPub: string]: DenominationRecord} = await (
this.q().iterIndex(Stores.denominations.exchangeBaseUrlIndex,
exchangeInfo.baseUrl)
.reduce((x: DenominationRecord,
.fold((x: DenominationRecord,
acc: typeof existingDenoms) => (acc[x.denomPub] = x, acc),
{})
);
@ -1995,19 +1993,19 @@ export class Wallet {
.iter(Stores.exchanges)
.indexJoin(Stores.denominations.exchangeBaseUrlIndex,
(x) => x.baseUrl)
.reduce(collectSmallestWithdraw, {}));
.fold(collectSmallestWithdraw, {}));
const tx = this.q();
tx.iter(Stores.coins)
.reduce(collectBalances, balanceStore);
.fold(collectBalances, balanceStore);
tx.iter(Stores.refresh)
.reduce(collectPendingRefresh, balanceStore);
.fold(collectPendingRefresh, balanceStore);
tx.iter(Stores.reserves)
.reduce(collectPendingWithdraw, balanceStore);
.fold(collectPendingWithdraw, balanceStore);
tx.iter(Stores.reserves)
.reduce(collectPaybacks, balanceStore);
.fold(collectPaybacks, balanceStore);
tx.iter(Stores.purchases)
.reduce(collectPayments, balanceStore);
.fold(collectPayments, balanceStore);
await tx.finish();
return balanceStore;
}

View File

@ -49,7 +49,7 @@ if (document.documentElement.getAttribute("data-taler-nojs")) {
interface Handler {
type: string;
listener: (e: CustomEvent) => void|Promise<void>;
listener: (e: Event) => void|Promise<void>;
}
const handlers: Handler[] = [];
@ -230,13 +230,6 @@ async function processProposal(proposal: any) {
return;
}
let merchantName = "(unknown)";
try {
merchantName = proposal.data.merchant.name;
} catch (e) {
// bad contract / name not included
}
const proposalId = await wxApi.saveProposal({
contractTerms: proposal.data,
contractTermsHash: proposal.hash,
@ -400,7 +393,10 @@ function registerHandlers() {
* handles adding sequence numbers to responses.
*/
function addHandler(type: string, handler: HandlerFn) {
const handlerWrap = (e: CustomEvent) => {
const handlerWrap = (e: Event) => {
if (!(e instanceof CustomEvent)) {
throw Error(`invariant violated`);
}
if (e.type !== type) {
throw Error(`invariant violated`);
}

View File

@ -44,8 +44,8 @@ interface ConfirmAuditorProps {
class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
private addDone: StateHolder<boolean> = this.makeState(false);
constructor() {
super();
constructor(props: ConfirmAuditorProps) {
super(props);
}
async add() {

View File

@ -39,9 +39,9 @@ interface CurrencyListState {
currencies?: CurrencyRecord[];
}
class CurrencyList extends React.Component<any, CurrencyListState> {
constructor() {
super();
class CurrencyList extends React.Component<{}, CurrencyListState> {
constructor(props: {}) {
super(props);
const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => {
if (msg.notify) {

View File

@ -118,8 +118,8 @@ interface ContractPromptState {
}
class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> {
constructor() {
super();
constructor(props: ContractPromptProps) {
super(props);
this.state = {
alreadyPaid: false,
error: null,

View File

@ -55,9 +55,9 @@ interface LogsState {
logs: LogEntry[]|undefined;
}
class Logs extends React.Component<any, LogsState> {
constructor() {
super();
class Logs extends React.Component<{}, LogsState> {
constructor(props: {}) {
super({});
this.update();
this.state = {} as any;
}

View File

@ -38,10 +38,10 @@ import {
import * as React from "react";
import * as ReactDOM from "react-dom";
class Payback extends ImplicitStateComponent<any> {
class Payback extends ImplicitStateComponent<{}> {
private reserves: StateHolder<ReserveRecord[]|null> = this.makeState(null);
constructor() {
super();
constructor(props: {}) {
super(props);
const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => {
if (msg.notify) {

View File

@ -189,9 +189,9 @@ interface ReturnCoinsState {
lastConfirmedDetail: SelectedDetail | undefined;
}
class ReturnCoins extends React.Component<any, ReturnCoinsState> {
constructor() {
super();
class ReturnCoins extends React.Component<{}, ReturnCoinsState> {
constructor(props: {}) {
super(props);
const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => {
if (msg.notify) {

View File

@ -360,9 +360,9 @@ interface ExchangesListState {
exchanges?: ExchangeRecord[];
}
class ExchangesList extends React.Component<any, ExchangesListState> {
constructor() {
super();
class ExchangesList extends React.Component<{}, ExchangesListState> {
constructor(props: {}) {
super(props);
const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => {
if (msg.notify) {

View File

@ -497,9 +497,8 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea
console.log("202 not understood (X-Taler-Callback-Url missing)");
return;
}
let amountParsed;
try {
amountParsed = JSON.parse(amount);
JSON.parse(amount);
} catch (e) {
const errUri = new URI(chrome.extension.getURL("/src/webex/pages/error.html"));
const p = {