From a1d67dd7fb7843530ad0665dda49a5f876f9eb08 Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Sat, 22 Apr 2023 18:39:12 +0200 Subject: [PATCH 1/2] fix: TypeScript errors for types --- src/structures/Amount.ts | 6 +++--- src/structures/CurrencyFormat.ts | 5 ++++- src/structures/CurrencyFormatUnits.ts | 24 ++++++++++++------------ src/structures/RequestHandler.ts | 2 +- src/structures/User.ts | 8 ++++---- src/structures/Wallet.ts | 2 +- src/utils/CacheHandler.ts | 2 +- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/structures/Amount.ts b/src/structures/Amount.ts index 63331ee..032a519 100644 --- a/src/structures/Amount.ts +++ b/src/structures/Amount.ts @@ -14,7 +14,7 @@ import FiatCurrency from './FiatCurrency'; export default class Amount { public value: BigNumber; - public currency?: CryptoCurrency | FiatCurrency; + public currency: CryptoCurrency | FiatCurrency | null; /** * Create an Amount. @@ -28,10 +28,10 @@ export default class Amount { this.value = BigNumber(payload.value); switch (currencyType) { case 'crypto': - this.currency = getCachedCryptoCurrency(payload.currency); + this.currency = getCachedCryptoCurrency(payload.currency) ?? null; break; case 'fiat': - this.currency = getCachedFiatCurrency(payload.currency); + this.currency = getCachedFiatCurrency(payload.currency) ?? null; break; } } diff --git a/src/structures/CurrencyFormat.ts b/src/structures/CurrencyFormat.ts index 5d46fd3..24b2d98 100644 --- a/src/structures/CurrencyFormat.ts +++ b/src/structures/CurrencyFormat.ts @@ -1,4 +1,7 @@ -import { APICryptoCurrency, APIFiatCurrency } from '@tipccjs/tipcc-api-types'; +import type { + APICryptoCurrency, + APIFiatCurrency, +} from '@tipccjs/tipcc-api-types'; import CryptoCurrencyUnit from './CurrencyFormatUnits'; /** diff --git a/src/structures/CurrencyFormatUnits.ts b/src/structures/CurrencyFormatUnits.ts index 187c645..c23830a 100644 --- a/src/structures/CurrencyFormatUnits.ts +++ b/src/structures/CurrencyFormatUnits.ts @@ -9,21 +9,21 @@ import type { export default class CurrencyUnit { public singular: string; - public plural?: string; + public plural: string | null; - public prefix?: string; + public prefix: string | null; - public suffix?: string; + public suffix: string | null; public scale: number; public aliases: string[]; - public minDecimals?: number; + public minDecimals: number | null; - public optionalDecimals?: boolean; + public optionalDecimals: boolean | null; - public min?: number; + public min: number | null; /** * Create a CryptoCurrencyUnit. @@ -31,13 +31,13 @@ export default class CurrencyUnit { */ constructor(payload: APIFiatCurrencyUnit | APICryptoCurrencyUnit) { this.singular = payload.singular; - this.plural = payload.plural ?? undefined; - this.prefix = payload.prefix; - this.suffix = payload.suffix; + this.plural = payload.plural ?? null; + this.prefix = payload.prefix ?? null; + this.suffix = payload.suffix ?? null; this.scale = payload.scale; this.aliases = payload.aliases ?? []; - this.minDecimals = payload.minDecimals; - this.optionalDecimals = payload.optionalDecimals; - this.min = payload.min; + this.minDecimals = payload.minDecimals ?? null; + this.optionalDecimals = payload.optionalDecimals ?? null; + this.min = payload.min ?? null; } } diff --git a/src/structures/RequestHandler.ts b/src/structures/RequestHandler.ts index 3487f23..98ce5e1 100644 --- a/src/structures/RequestHandler.ts +++ b/src/structures/RequestHandler.ts @@ -23,7 +23,7 @@ export default class RequestHandler { constructor( apiKey: string, payload: { - apiBaseUrl?: string; + apiBaseUrl?: string | undefined; } = {}, ) { this._apiBaseUrl = payload.apiBaseUrl ?? 'https://api.tip.cc/api/v0'; diff --git a/src/structures/User.ts b/src/structures/User.ts index a8fe991..9a774ec 100644 --- a/src/structures/User.ts +++ b/src/structures/User.ts @@ -6,9 +6,9 @@ import type { APIConnection } from '@tipccjs/tipcc-api-types'; export default class User { public identifier: string; - public username?: string; + public username: string | null; - public avatarUrl?: string; + public avatarUrl: string | null; public service: 'discord'; @@ -18,8 +18,8 @@ export default class User { */ constructor(payload: APIConnection) { this.identifier = payload.identifier; - this.username = payload.username; - this.avatarUrl = payload.avatar_url; + this.username = payload.username ?? null; + this.avatarUrl = payload.avatar_url ?? null; this.service = payload.service; } } diff --git a/src/structures/Wallet.ts b/src/structures/Wallet.ts index 067b825..6e43bd6 100644 --- a/src/structures/Wallet.ts +++ b/src/structures/Wallet.ts @@ -1,4 +1,4 @@ -import { APIWallet } from '@tipccjs/tipcc-api-types'; +import type { APIWallet } from '@tipccjs/tipcc-api-types'; import Amount from './Amount'; /** diff --git a/src/utils/CacheHandler.ts b/src/utils/CacheHandler.ts index feb3239..33e56d3 100644 --- a/src/utils/CacheHandler.ts +++ b/src/utils/CacheHandler.ts @@ -1,4 +1,4 @@ -import { +import type { RESTGetAPICurrenciesCryptoCurrenciesResult, RESTGetAPICurrenciesFiatsResult, } from '@tipccjs/tipcc-api-types'; From 8fda6d0735367089e9e127f6a9f67c324144af5a Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Sat, 22 Apr 2023 18:51:25 +0200 Subject: [PATCH 2/2] build: Add exactOptionalPropertyTypes back --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index b0d7c2f..0d0b50a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "removeComments": false, "strictNullChecks": true, "preserveConstEnums": true, + "exactOptionalPropertyTypes": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true },