Add "strict": true to tsconfig.json (#994)

- Remove process.browser
This commit is contained in:
Elliot Lee
2019-04-11 15:48:23 -07:00
committed by GitHub
parent 1abcef73a0
commit 50fc36ec3e
40 changed files with 76 additions and 74 deletions

View File

@@ -1,9 +0,0 @@
/**
* This is an extension of Node's `process` object to include the browser
* property, which is added by webpack.
*/
interface AmbiguousProcess extends NodeJS.Process {
browser?: true
}
declare var process: AmbiguousProcess;

View File

@@ -30,7 +30,7 @@
"ws": "^3.3.1"
},
"devDependencies": {
"@types/node": "^8.0.53",
"@types/node": "11.13.0",
"assert-diff": "^1.0.1",
"doctoc": "^0.15.0",
"ejs": "^2.3.4",
@@ -50,7 +50,7 @@
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"tslint-eslint-rules": "^4.1.1",
"typescript": "2.9.2",
"typescript": "3.4.2",
"uglifyjs-webpack-plugin": "^1.1.4",
"webpack": "3.12.0",
"yargs": "^8.0.2"

View File

@@ -206,12 +206,6 @@ class Connection extends EventEmitter {
this._retry = 0
this._ws.on('error', error => {
// TODO: "type" does not exist on official error type, safe to remove?
if (process.browser && error && (<any>error).type === 'error') {
// we are in browser, ignore error - `close` event will be fired
// after error
return
}
this.emit('error', 'websocket', error.message, error)
})
@@ -287,7 +281,7 @@ class Connection extends EventEmitter {
return websocket
}
connect() {
connect(): Promise<void> {
this._clearReconnectTimer()
return new Promise((resolve, reject) => {
if (!this._url) {
@@ -322,11 +316,11 @@ class Connection extends EventEmitter {
})
}
disconnect() {
disconnect(): Promise<void> {
return this._disconnect(true)
}
_disconnect(calledByUser) {
_disconnect(calledByUser): Promise<void> {
if (calledByUser) {
this._clearReconnectTimer()
this._retry = 0

View File

@@ -1,7 +1,7 @@
import * as _ from 'lodash'
import {convertKeysFromSnakeCaseToCamelCase} from './utils'
import BigNumber from 'bignumber.js'
import {RippleAPI} from '../index'
import {RippleAPI} from '..'
export type GetServerInfoResponse = {
buildVersion: string,

View File

@@ -1,5 +1,5 @@
import {validate, removeUndefined, dropsToXrp} from '../common'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {AccountInfoResponse} from '../common/types/commands/account_info'
export type GetAccountInfoOptions = {

View File

@@ -1,5 +1,5 @@
import {removeUndefined} from '../common'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {
GetAccountObjectsOptions,
AccountObjectsResponse

View File

@@ -2,7 +2,7 @@ import * as _ from 'lodash'
import {validate} from '../common'
import {Amount} from '../common/types/objects'
import {ensureLedgerVersion} from './utils'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
export type BalanceSheetOptions = {
excludeAddresses?: Array<string>,

View File

@@ -3,6 +3,7 @@ import {validate} from '../common'
import {Connection} from '../common'
import {GetTrustlinesOptions} from './trustlines'
import {FormattedTrustline} from '../common/types/objects/trustlines'
import {RippleAPI} from '..'
export type Balance = {
@@ -47,7 +48,7 @@ function getLedgerVersionHelper(connection: Connection, optionValue?: number
return connection.getLedgerVersion()
}
function getBalances(address: string, options: GetTrustlinesOptions = {}
function getBalances(this: RippleAPI, address: string, options: GetTrustlinesOptions = {}
): Promise<GetBalances> {
validate.getTrustlines({address, options})

View File

@@ -1,6 +1,6 @@
import {validate} from '../common'
import {FormattedLedger, parseLedger} from './parse/ledger'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
export type GetLedgerOptions = {
ledgerHash?: string,

View File

@@ -7,7 +7,7 @@ import {
import {validate} from '../common'
import {Amount, Issue} from '../common/types/objects'
import {BookOffer} from '../common/types/commands'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import BigNumber from 'bignumber.js'
export type FormattedOrderbook = {

View File

@@ -1,7 +1,7 @@
import * as _ from 'lodash'
import {validate} from '../common'
import {FormattedAccountOrder, parseAccountOrder} from './parse/account-order'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {AccountOffersResponse} from '../common/types/commands'
export type GetOrdersOptions = {

View File

@@ -14,6 +14,7 @@ import {RippledAmount, Amount} from '../common/types/objects'
import {
GetPaths, PathFind, RippledPathsResponse, PathFindRequest
} from './pathfind-types'
import {RippleAPI} from '..'
const NotFoundError = errors.NotFoundError
const ValidationError = errors.ValidationError
@@ -147,7 +148,7 @@ function formatResponse(pathfind: PathFind, paths: RippledPathsResponse) {
}
}
function getPaths(pathfind: PathFind): Promise<GetPaths> {
function getPaths(this: RippleAPI, pathfind: PathFind): Promise<GetPaths> {
validate.getPaths({pathfind})
const address = pathfind.source.address

View File

@@ -3,7 +3,7 @@ import {
FormattedPaymentChannel
} from './parse/payment-channel'
import {validate, errors} from '../common'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {LedgerEntryResponse} from '../common/types/commands'
const NotFoundError = errors.NotFoundError

View File

@@ -3,7 +3,7 @@ import parseFields from './parse/fields'
import {validate, constants} from '../common'
import {FormattedSettings} from '../common/types/objects'
import {AccountInfoResponse} from '../common/types/commands'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
const AccountFlags = constants.AccountFlags
export type SettingsOptions = {

View File

@@ -5,6 +5,7 @@ import {validate, errors} from '../common'
import {Connection} from '../common'
import {FormattedTransactionType} from '../transaction/types'
import {RippledError} from '../common/errors'
import {RippleAPI} from '..'
export type TransactionOptions = {
minLedgerVersion?: number,
@@ -96,7 +97,7 @@ function formatResponse(options: TransactionOptions, tx: TransactionResponse
return parseTransaction(tx, options.includeRawTransaction)
}
async function getTransaction(id: string, options: TransactionOptions = {}
async function getTransaction(this: RippleAPI, id: string, options: TransactionOptions = {}
): Promise<FormattedTransactionType> {
validate.getTransaction({id, options})
const _options = await utils.ensureLedgerVersion.call(this, options)

View File

@@ -6,6 +6,7 @@ import parseTransaction from './parse/transaction'
import getTransaction from './transaction'
import {validate, errors, Connection} from '../common'
import {FormattedTransactionType} from '../transaction/types'
import {RippleAPI} from '..'
export type TransactionsOptions = {
@@ -162,7 +163,7 @@ function getTransactionsInternal(connection: Connection, address: string,
return utils.getRecursive(getter, options.limit).then(format)
}
function getTransactions(address: string, options: TransactionsOptions = {}
function getTransactions(this: RippleAPI, address: string, options: TransactionsOptions = {}
): Promise<GetTransactionsResponse> {
validate.getTransactions({address, options})

View File

@@ -1,7 +1,7 @@
import * as _ from 'lodash'
import {validate} from '../common'
import parseAccountTrustline from './parse/account-trustline'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {FormattedTrustline} from '../common/types/objects/trustlines'
export type GetTrustlinesOptions = {

View File

@@ -4,6 +4,7 @@ import * as common from '../common'
import {Connection} from '../common'
import {FormattedTransactionType} from '../transaction/types'
import {Issue} from '../common/types/objects'
import {RippleAPI} from '..'
export type RecursiveData = {
marker: string,
@@ -105,7 +106,7 @@ function isPendingLedgerVersion(connection: Connection,
ledgerVersion < (maxLedgerVersion || 0))
}
function ensureLedgerVersion(options: any
function ensureLedgerVersion(this: RippleAPI, options: any
): Promise<object> {
if (Boolean(options) && options.ledgerVersion !== undefined &&
options.ledgerVersion !== null

View File

@@ -1,18 +1,19 @@
import * as common from '../common'
import {RippleAPI} from '..'
function isConnected(): boolean {
function isConnected(this: RippleAPI): boolean {
return this.connection.isConnected()
}
function getLedgerVersion(): Promise<number> {
function getLedgerVersion(this: RippleAPI): Promise<number> {
return this.connection.getLedgerVersion()
}
function connect(): Promise<void> {
function connect(this: RippleAPI): Promise<void> {
return this.connection.connect()
}
function disconnect(): Promise<void> {
function disconnect(this: RippleAPI): Promise<void> {
return this.connection.disconnect()
}

View File

@@ -1,6 +1,7 @@
import {TransactionJSON, prepareTransaction} from './utils'
import {validate} from '../common'
import {Instructions, Prepare} from './types'
import {RippleAPI} from '..'
export type CheckCancelParameters = {
checkID: string
@@ -18,7 +19,7 @@ function createCheckCancelTransaction(account: string,
return txJSON
}
function prepareCheckCancel(address: string,
function prepareCheckCancel(this: RippleAPI, address: string,
checkCancel: CheckCancelParameters,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -4,6 +4,7 @@ const toRippledAmount = utils.common.toRippledAmount
import {validate} from '../common'
import {Instructions, Prepare, TransactionJSON} from './types'
import {Amount} from '../common/types/objects'
import {RippleAPI} from '..'
export type CheckCashParameters = {
checkID: string,
@@ -36,7 +37,7 @@ function createCheckCashTransaction(account: string,
return txJSON
}
function prepareCheckCash(address: string,
function prepareCheckCash(this: RippleAPI, address: string,
checkCash: CheckCashParameters,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -3,6 +3,7 @@ const toRippledAmount = utils.common.toRippledAmount
import {validate, iso8601ToRippleTime} from '../common'
import {Instructions, Prepare, TransactionJSON} from './types'
import {Amount} from '../common/types/objects'
import {RippleAPI} from '..'
export type CheckCreateParameters = {
destination: string,
@@ -37,7 +38,7 @@ function createCheckCreateTransaction(account: string,
return txJSON
}
function prepareCheckCreate(address: string,
function prepareCheckCreate(this: RippleAPI, address: string,
checkCreate: CheckCreateParameters,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -2,6 +2,7 @@ import * as utils from './utils'
const validate = utils.common.validate
import {Instructions, Prepare, TransactionJSON} from './types'
import {Memo} from '../common/types/objects'
import {RippleAPI} from '..'
export type EscrowCancellation = {
owner: string,
@@ -27,7 +28,7 @@ function createEscrowCancellationTransaction(account: string,
return txJSON
}
function prepareEscrowCancellation(address: string,
function prepareEscrowCancellation(this: RippleAPI, address: string,
escrowCancellation: EscrowCancellation,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -3,6 +3,7 @@ import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
const ValidationError = utils.common.errors.ValidationError
import {Instructions, Prepare, TransactionJSON} from './types'
import {Memo} from '../common/types/objects'
import {RippleAPI} from '..'
export type EscrowCreation = {
amount: string,
@@ -51,7 +52,7 @@ function createEscrowCreationTransaction(account: string,
return txJSON
}
function prepareEscrowCreation(address: string,
function prepareEscrowCreation(this: RippleAPI, address: string,
escrowCreation: EscrowCreation,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -3,6 +3,7 @@ const validate = utils.common.validate
const ValidationError = utils.common.errors.ValidationError
import {Instructions, Prepare} from './types'
import {Memo} from '../common/types/objects'
import {RippleAPI} from '..'
export type EscrowExecution = {
owner: string,
@@ -39,7 +40,7 @@ function createEscrowExecutionTransaction(account: string,
return txJSON
}
function prepareEscrowExecution(address: string,
function prepareEscrowExecution(this: RippleAPI, address: string,
escrowExecution: EscrowExecution,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -3,6 +3,7 @@ const offerFlags = utils.common.txFlags.OfferCreate
import {validate, iso8601ToRippleTime} from '../common'
import {Instructions, Prepare, OfferCreateTransaction} from './types'
import {FormattedOrderSpecification} from '../common/types/objects/index'
import {RippleAPI} from '..'
function createOrderTransaction(
account: string, order: FormattedOrderSpecification
@@ -43,7 +44,7 @@ function createOrderTransaction(
return txJSON as OfferCreateTransaction
}
function prepareOrder(address: string, order: FormattedOrderSpecification,
function prepareOrder(this: RippleAPI, address: string, order: FormattedOrderSpecification,
instructions: Instructions = {}
): Promise<Prepare> {
try {

View File

@@ -1,6 +1,7 @@
import * as utils from './utils'
const validate = utils.common.validate
import {Instructions, Prepare, TransactionJSON} from './types'
import {RippleAPI} from '..'
function createOrderCancellationTransaction(account: string,
orderCancellation: any
@@ -16,7 +17,7 @@ function createOrderCancellationTransaction(account: string,
return txJSON
}
function prepareOrderCancellation(address: string, orderCancellation: object,
function prepareOrderCancellation(this: RippleAPI, address: string, orderCancellation: object,
instructions: Instructions = {}
): Promise<Prepare> {
try {

View File

@@ -3,6 +3,7 @@ const ValidationError = utils.common.errors.ValidationError
const claimFlags = utils.common.txFlags.PaymentChannelClaim
import {validate, xrpToDrops} from '../common'
import {Instructions, Prepare} from './types'
import {RippleAPI} from '..'
export type PaymentChannelClaim = {
channel: string,
@@ -58,7 +59,7 @@ function createPaymentChannelClaimTransaction(account: string,
return txJSON
}
function preparePaymentChannelClaim(address: string,
function preparePaymentChannelClaim(this: RippleAPI, address: string,
paymentChannelClaim: PaymentChannelClaim,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -1,6 +1,7 @@
import * as utils from './utils'
import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
import {Instructions, Prepare} from './types'
import {RippleAPI} from '..'
export type PaymentChannelCreate = {
amount: string,
@@ -37,7 +38,7 @@ function createPaymentChannelCreateTransaction(account: string,
return txJSON
}
function preparePaymentChannelCreate(address: string,
function preparePaymentChannelCreate(this: RippleAPI, address: string,
paymentChannelCreate: PaymentChannelCreate,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -1,6 +1,7 @@
import * as utils from './utils'
import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
import {Instructions, Prepare} from './types'
import {RippleAPI} from '..'
export type PaymentChannelFund = {
channel: string,
@@ -25,7 +26,7 @@ function createPaymentChannelFundTransaction(account: string,
return txJSON
}
function preparePaymentChannelFund(address: string,
function preparePaymentChannelFund(this: RippleAPI, address: string,
paymentChannelFund: PaymentChannelFund,
instructions: Instructions = {}
): Promise<Prepare> {

View File

@@ -8,6 +8,7 @@ import {Instructions, Prepare, TransactionJSON} from './types'
import {Amount, Adjustment, MaxAdjustment,
MinAdjustment, Memo} from '../common/types/objects'
import {xrpToDrops} from '../common'
import {RippleAPI} from '..'
export interface Payment {
@@ -167,7 +168,7 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
return txJSON
}
function preparePayment(address: string, payment: Payment,
function preparePayment(this: RippleAPI, address: string, payment: Payment,
instructions: Instructions = {}
): Promise<Prepare> {
try {

View File

@@ -6,6 +6,7 @@ const AccountFlagIndices = utils.common.constants.AccountFlagIndices
const AccountFields = utils.common.constants.AccountFields
import {Instructions, Prepare, SettingsTransaction} from './types'
import {FormattedSettings, WeightedSigner} from '../common/types/objects'
import {RippleAPI} from '..'
function setTransactionFlags(txJSON: utils.TransactionJSON, values: FormattedSettings) {
const keys = Object.keys(values)
@@ -121,7 +122,7 @@ function createSettingsTransaction(account: string, settings: FormattedSettings
return txJSON
}
function prepareSettings(address: string, settings: FormattedSettings,
function prepareSettings(this: RippleAPI, address: string, settings: FormattedSettings,
instructions: Instructions = {}
): Promise<Prepare> {
try {

View File

@@ -5,7 +5,7 @@ import {computeBinaryTransactionHash} from 'ripple-hashes'
import {SignOptions, KeyPair} from './types'
import {BigNumber} from 'bignumber.js'
import {xrpToDrops} from '../common'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
const validate = utils.common.validate
function computeSignature(tx: object, privateKey: string, signAs?: string) {

View File

@@ -6,6 +6,7 @@ import {Instructions, Prepare, TransactionJSON} from './types'
import {
FormattedTrustlineSpecification
} from '../common/types/objects/trustlines'
import {RippleAPI} from '..'
function convertQuality(quality) {
return (new BigNumber(quality)).shift(9).truncated().toNumber()
@@ -49,7 +50,7 @@ function createTrustlineTransaction(account: string,
return txJSON
}
function prepareTrustline(address: string,
function prepareTrustline(this: RippleAPI, address: string,
trustline: FormattedTrustlineSpecification, instructions: Instructions = {}
): Promise<Prepare> {
try {

View File

@@ -3,7 +3,7 @@ import * as common from '../common'
import {Memo, RippledAmount} from '../common/types/objects'
const txFlags = common.txFlags
import {Instructions, Prepare} from './types'
import {RippleAPI} from '../api'
import {RippleAPI} from '..'
import {ValidationError} from '../common/errors'
export type ApiMemo = {

View File

@@ -15,11 +15,11 @@ const utils = RippleAPI._PRIVATE.ledgerUtils;
const ledgerClosed = require('./fixtures/rippled/ledger-close-newer');
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
const binary = require('ripple-binary-codec');
const BigNumber = require('bignumber.js')
const BigNumber = require('bignumber.js');
assert.options.strict = true;
// how long before each test case times out
const TIMEOUT = process.browser ? 25000 : 10000;
const TIMEOUT = 20000;
function unused() {
}

View File

@@ -8,7 +8,7 @@ const ledgerClosed = require('./fixtures/rippled/ledger-close');
const RippleAPI = require('ripple-api').RippleAPI;
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
const TIMEOUT = process.browser ? 25000 : 10000;
const TIMEOUT = 20000;
function checkResult(expected, schemaName, response) {
if (expected.txJSON) {
@@ -29,9 +29,7 @@ describe('RippleAPIBroadcast', function() {
it('base', function() {
const expected = {request_server_info: 1};
if (!process.browser) {
this.mocks.forEach(mock => mock.expect(_.assign({}, expected)));
}
this.mocks.forEach(mock => mock.expect(_.assign({}, expected)));
assert(this.api.isConnected());
return this.api.getServerInfo().then(
_.partial(checkResult, responses.getServerInfo, 'getServerInfo'));

View File

@@ -13,7 +13,7 @@ const {payTo, ledgerAccept} = require('./utils');
// how long before each test case times out
const TIMEOUT = process.browser ? 25000 : 10000;
const TIMEOUT = 20000;
const INTERVAL = 1000; // how long to wait between checks for validated ledger
const serverUrl = 'ws://127.0.0.1:6006';

View File

@@ -12,15 +12,14 @@
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"removeComments": true,
"strict": true /* Enable all strict type-checking options. */,
"preserveConstEnums": false,
"suppressImplicitAnyIndexErrors": false,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true
"sourceMap": true
},
"include": [
"custom_typings/**/*.ts",
"src/**/*.ts"
]
}

View File

@@ -12,10 +12,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.1.tgz#e2d374ef15b315b48e7efc308fa1a7cd51faa06c"
integrity sha512-xwlHq5DXQFRpe+u6hmmNkzYk/3oxxqDp71a/AJMupOQYmxyaBetqrVMqdNlSQfbg7XTJYD8vARjf3Op06OzdtQ==
"@types/node@^8.0.53":
version "8.10.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.1.tgz#aac98b810c50568054486f2bb8c486d824713be8"
integrity sha512-X/pIUOcgpX7xxKsmdPCMKeDBefsGH/4D/IuJ1gIHbqgWI0qEy/yMKeqaN/sT+rzV9UpAXAfd0kLOVExRmZrXIg==
"@types/node@11.13.0":
version "11.13.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.13.0.tgz#b0df8d6ef9b5001b2be3a94d909ce3c29a80f9e1"
integrity sha512-rx29MMkRdVmzunmiA4lzBYJNnXsW/PhG4kMBy2ATsYaDjGGR75dCFEVVROKpNwlVdcUX3xxlghKQOeDPBJobng==
"@types/ws@^3.2.0":
version "3.2.1"
@@ -5223,10 +5223,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
typescript@2.9.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==
typescript@3.4.2:
version "3.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.2.tgz#9ed4e6475d906f589200193be056f5913caed481"
integrity sha512-Og2Vn6Mk7JAuWA1hQdDQN/Ekm/SchX80VzLhjKN9ETYrIepBFAd8PkOdOTK2nKt0FCkmMZKBJvQ1dV1gIxPu/A==
uglify-es@^3.3.4:
version "3.3.9"