Skip to content

Commit 194588f

Browse files
authored
Merge pull request #1803 from aeternity/feature/ts-strict
Enable strict mode except for `strictFunctionTypes`
2 parents 7859338 + 6cbaaf5 commit 194588f

File tree

15 files changed

+57
-45
lines changed

15 files changed

+57
-45
lines changed

src/AeSdkMethods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Object.assign(AeSdkMethods.prototype, mapObject<Function, Function>(
147147
methods,
148148
([name, handler]) => [
149149
name,
150-
function methodWrapper(...args: any[]) {
150+
function methodWrapper(this: AeSdkMethods, ...args: any[]) {
151151
args.length = handler.length;
152152
const options = args[args.length - 1];
153153
args[args.length - 1] = {

src/AeSdkWallet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from './aepp-wallet-communication/rpc/types';
2121
import { Encoded } from './utils/encoder';
2222
import jsonBig from './utils/json-big';
23+
import { ensureError } from './utils/other';
2324

2425
type RpcClientWallet = RpcClient<AeppApi, WalletApi>;
2526

@@ -259,6 +260,7 @@ export default class AeSdkWallet extends AeSdk {
259260
} catch (error) {
260261
const validation = await verifyTransaction(tx, this.api);
261262
if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
263+
ensureError(error);
262264
throw new RpcBroadcastError(error.message);
263265
}
264266
},

src/account/Base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ export default abstract class AccountBase {
6363
/**
6464
* Account address
6565
*/
66-
readonly address: Encoded.AccountAddress;
66+
readonly address!: Encoded.AccountAddress;
6767
}

src/aepp-wallet-communication/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const rpcErrors: Array<(new (data?: any) => RpcError) & { code: number }> = [];
6464
export abstract class RpcError extends BaseError {
6565
static code: number;
6666

67-
code: number;
67+
code!: number;
6868

6969
data?: any;
7070

src/chain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter';
22
import verifyTransaction, { ValidatorResult } from './tx/validator';
3-
import { isAccountNotFoundError, pause } from './utils/other';
3+
import { ensureError, isAccountNotFoundError, pause } from './utils/other';
44
import { isNameValid, produceNameId } from './tx/builder/helpers';
55
import { DRY_RUN_ACCOUNT } from './tx/builder/schema';
66
import { AensName } from './tx/builder/constants';
@@ -208,6 +208,7 @@ export async function sendTransaction(
208208
}
209209
return { hash: txHash, rawTx: tx };
210210
} catch (error) {
211+
ensureError(error);
211212
throw Object.assign(error, {
212213
rawTx: tx,
213214
verifyTx: async () => verifyTransaction(tx, onNode),

src/channel/Base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function snakeToPascalObjKeys<Type>(obj: object): Type {
5555
export default class Channel {
5656
_eventEmitter = new EventEmitter();
5757

58-
_pingTimeoutId: NodeJS.Timeout;
58+
_pingTimeoutId!: NodeJS.Timeout;
5959

6060
_nextRpcMessageId = 0;
6161

@@ -73,13 +73,13 @@ export default class Channel {
7373

7474
_status: ChannelStatus = 'disconnected';
7575

76-
_fsm: ChannelFsm;
76+
_fsm!: ChannelFsm;
7777

78-
_websocket: W3CWebSocket;
78+
_websocket!: W3CWebSocket;
7979

8080
_state: Encoded.Transaction | '' = '';
8181

82-
_options: ChannelOptions;
82+
_options!: ChannelOptions;
8383

8484
_channelId?: Encoded.Channel;
8585

src/channel/internal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../utils/errors';
1616
import { encodeContractAddress } from '../utils/crypto';
1717
import { buildTx } from '../tx/builder';
18+
import { ensureError } from '../utils/other';
1819

1920
export interface ChannelEvents {
2021
statusChanged: (status: ChannelStatus) => void;
@@ -240,6 +241,7 @@ async function dequeueMessage(channel: Channel): Promise<void> {
240241
try {
241242
await handleMessage(channel, message);
242243
} catch (error) {
244+
ensureError(error);
243245
emit(channel, 'error', new ChannelIncomingMessageError(error, message));
244246
}
245247
}

src/contract/compiler/Cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import CompilerBase, { Aci } from './Base';
77
import { Encoded } from '../../utils/encoder';
88
import { CompilerError, InternalError, UnsupportedVersionError } from '../../utils/errors';
99
import semverSatisfies from '../../utils/semver-satisfies';
10+
import { ensureError } from '../../utils/other';
1011

1112
const getPackagePath = (): string => {
1213
const path = dirname(fileURLToPath(import.meta.url));
@@ -22,7 +23,7 @@ const getPackagePath = (): string => {
2223
export default class CompilerCli extends CompilerBase {
2324
#path: string;
2425

25-
#ensureCompatibleVersion: Promise<void>;
26+
#ensureCompatibleVersion = Promise.resolve();
2627

2728
constructor(
2829
compilerPath = resolve(getPackagePath(), './bin/aesophia_cli'),
@@ -81,6 +82,7 @@ export default class CompilerCli extends CompilerBase {
8182
aci: aci as Aci,
8283
};
8384
} catch (error) {
85+
ensureError(error);
8486
throw new CompilerError(error.message);
8587
}
8688
}

src/tx/builder/field-types/coin-amount.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter
55
export default {
66
...uInt,
77

8-
serializeAettos(value: string | undefined): string {
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9+
serializeAettos(value: string | undefined, params: {}): string {
910
return value ?? '0';
1011
},
1112

src/tx/validator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RestError } from '@azure/core-rest-pipeline';
12
import { hash, verify } from '../utils/crypto';
23
import { TxUnpacked } from './builder/schema.generated';
34
import { CtVersion, ProtocolToVmAbi } from './builder/field-types/ct-version';
@@ -183,9 +184,9 @@ validators.push(
183184
checkedKeys: ['contractId'],
184185
}];
185186
} catch (error) {
186-
if (error.response?.parsedBody?.reason == null) throw error;
187+
if (!(error instanceof RestError) || error.response?.bodyAsText == null) throw error;
187188
return [{
188-
message: error.response.parsedBody.reason,
189+
message: JSON.parse(error.response.bodyAsText).reason, // TODO: use parsedBody instead
189190
key: 'ContractNotFound',
190191
checkedKeys: ['contractId'],
191192
}];

0 commit comments

Comments
 (0)