Skip to content

Commit

Permalink
Remove @ts-ignores resolved with updated ts; change others to @ts-exp…
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Sep 6, 2024
1 parent 4c1cd7e commit c415852
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 41 deletions.
5 changes: 2 additions & 3 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ async function runKeyguard(RequestApiClass, opts) { // eslint-disable-line no-un

// Back arrow functionality
document.body.addEventListener('click', event => {
// @ts-ignore (Property 'matches' does not exist on type 'EventTarget'.)
if (!event.target || !event.target.matches('a.page-header-back-button')) return;
if (!(event.target instanceof HTMLElement && event.target.matches('a.page-header-back-button'))) return;
window.history.back();
});

Expand Down Expand Up @@ -125,7 +124,7 @@ async function runKeyguard(RequestApiClass, opts) { // eslint-disable-line no-un
window.rpcServer = new RpcServer(CONFIG.ALLOWED_ORIGIN);

options.whitelist.forEach(/** @param {string} method */ method => {
// @ts-ignore (Element implicitly has an 'any' type because type 'TopLevelApi' has no index signature.)
// @ts-expect-error (Element implicitly has an 'any' type because type 'TopLevelApi' has no index signature.)
window.rpcServer.onRequest(method, api[method].bind(api));
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/RecoveryWordsInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RecoveryWordsInputField extends Nimiq.Observable {
* @param {ClipboardEvent} e
*/
_onPaste(e) {
// @ts-ignore (Property 'clipboardData' does not exist on type 'Window'.)
// @ts-expect-error (Property 'clipboardData' does not exist on type 'Window'.)
let paste = (e.clipboardData || window.clipboardData).getData('text');
paste = paste.replace(/\s+/g, ' ');
if (paste && paste.split(' ').length > 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (!/^(?:localhost|bs-local.com)$/.test(window.location.hostname) && !ipRegEx.t
throw new Error('Using development config is only allowed locally');
}

// @ts-ignore
// @ts-expect-error (ts thinks CONFIG is redeclared in other config files as it doesn't know that only one is active)
const CONFIG = { // eslint-disable-line no-unused-vars
ALLOWED_ORIGIN: '*',
NETWORK: Constants.NETWORK.TEST,
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.mainnet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Constants */

// @ts-ignore
// @ts-expect-error (ts thinks CONFIG is redeclared in other config files as it doesn't know that only one is active)
const CONFIG = { // eslint-disable-line no-unused-vars
ALLOWED_ORIGIN: 'https://hub.nimiq.com',
NETWORK: Constants.NETWORK.MAIN,
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.testnet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Constants */

// @ts-ignore
// @ts-expect-error (ts thinks CONFIG is redeclared in other config files as it doesn't know that only one is active)
const CONFIG = { // eslint-disable-line no-unused-vars
ALLOWED_ORIGIN: 'https://hub.nimiq-testnet.com',
NETWORK: Constants.NETWORK.TEST,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/BrowserDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BrowserDetection { // eslint-disable-line no-unused-vars
* @returns {boolean}
*/
static isIOS() {
// @ts-ignore (MSStream is not on window)
// @ts-expect-error (MSStream is not on window)
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/ClipboardUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ClipboardUtils { // eslint-disable-line no-unused-vars
// Prevent keyboard from showing on mobile
element.setAttribute('readonly', '');

// @ts-ignore: css property contain not known to current ts version
element.style.contain = 'strict';
element.style.position = 'absolute';
element.style.left = '-9999px';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/CookieStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ CookieStorage.ENCRYPTION_ALGORITHM = 'AES-GCM';
CookieStorage.ENCRYPTION_KEY_SIZE = 256 / 8;
// 12 bytes; as recommended in 5.2.1.1 of https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
CookieStorage.ENCRYPTION_INIT_VECTOR_SIZE = 96 / 8;
// @ts-ignore _calculateEncodedMetadataSize is private
// @ts-expect-error _calculateEncodedMetadataSize is private
CookieStorage.MAX_ENCODED_METADATA_SIZE = CookieStorage._calculateEncodedMetadataSize({
isEncrypted: true,
chunkCount: 1,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/CurrencyInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class CurrencyInfo {
let supportsDisplayNames = 'DisplayNames' in Intl;
// also normalizes the locales
[this.locale] = supportsDisplayNames
// @ts-ignore TODO use proper types once https://github.com/microsoft/TypeScript/pull/44022 is available
? Intl.DisplayNames.supportedLocalesOf(nameLocalesToTry)
: Intl.NumberFormat.supportedLocalesOf(nameLocalesToTry);
if (supportsDisplayNames && !this.locale) {
Expand Down Expand Up @@ -90,8 +89,7 @@ class CurrencyInfo {
if (supportsDisplayNames) {
try {
// Use DisplayNames if available as it provides better names.
// @ts-ignore TODO use proper types once https://github.com/microsoft/TypeScript/pull/44022 is merged
this.name = new Intl.DisplayNames(this.locale, { type: 'currency' }).of(currencyCode);
this.name = new Intl.DisplayNames(this.locale, { type: 'currency' }).of(currencyCode) || '';
} catch (e) {
// Ignore and continue with if block below.
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/QrScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ class QrScanner {

// Allow inline playback on iPhone instead of requiring full screen playback,
// see https://webkit.org/blog/6784/new-video-policies-for-ios/
// @ts-ignore Property 'playsInline' does not exist on type 'HTMLVideoElement'
this.$video.playsInline = true;
// Allow play() on iPhone without requiring a user gesture. Should not really be needed as camera stream
// includes no audio, but just to be safe.
this.$video.muted = true;
// @ts-ignore Property 'disablePictureInPicture' does not exist on type 'HTMLVideoElement'
this.$video.disablePictureInPicture = true;
this.$video.addEventListener('play', this._onPlay);
this.$video.addEventListener('loadedmetadata', this._onLoadedMetaData);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bitcoin/BitcoinKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class BitcoinKey { // eslint-disable-line no-unused-vars
const mnemonic = Nimiq.MnemonicUtils.entropyToMnemonic(this.secret);
const seed = Nimiq.MnemonicUtils.mnemonicToSeed(mnemonic);

// @ts-ignore Argument of type 'import("...").Buffer' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'import("...").Buffer' is not assignable to parameter of type 'Buffer'.
const master = BitcoinJS.bip32.fromSeed(BitcoinJS.Buffer.from(seed), network);
return master.derivePath(path);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bitcoin/BitcoinRequestParserMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function BitcoinRequestParserMixin(clazz) {
: undefined,
keyPath: this.parseBitcoinPath(input.keyPath, `input[${index}].keypath`),
// Address added only for display
// @ts-ignore Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
address: BitcoinJS.address.fromOutputScript(script, BitcoinUtils.Network),
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bitcoin/BitcoinUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ class BitcoinUtils { // eslint-disable-line no-unused-vars

if (bip === BitcoinConstants.BIP.BIP49) {
return BitcoinJS.address.toBase58Check(
// @ts-ignore Argument of type 'Uint8Array | Buffer' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array | Buffer' is not assignable to type 'Buffer'.
bytes,
BitcoinConstants.BIP49_ADDRESS_VERSIONS[CONFIG.BTC_NETWORK][1], // 0 => BIP44, 1 => BIP49
);
}

if (bip === BitcoinConstants.BIP.BIP84) {
return BitcoinJS.address.toBech32(
// @ts-ignore Argument of type 'Uint8Array | Buffer' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array | Buffer' is not assignable to type 'Buffer'.
bytes,
BitcoinConstants.BIP84_ADDRESS_VERSION,
BitcoinConstants.BIP84_ADDRESS_PREFIX[CONFIG.BTC_NETWORK],
Expand Down
6 changes: 3 additions & 3 deletions src/lib/swap/HtlcUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HtlcUtils { // eslint-disable-line no-unused-vars
const error = new Errors.InvalidRequestError('Invalid BTC HTLC script');

if (!script || !(script instanceof Uint8Array) || !script.length) throw error;
// @ts-ignore Type 'import(...).Buffer' is not assignable to type 'Buffer'.
// @ts-expect-error Type 'import(...).Buffer' is not assignable to type 'Buffer'.
const chunks = BitcoinJS.script.decompile(BitcoinJS.Buffer.from(script));
if (!chunks) throw error;
const asm = BitcoinJS.script.toASM(chunks).split(' ');
Expand Down Expand Up @@ -77,7 +77,7 @@ class HtlcUtils { // eslint-disable-line no-unused-vars
// Check timeout
// Bitcoin HTLC timeouts are backdated 1 hour, to account for Bitcoin's
// minimum age for valid transaction locktimes (6 blocks).
// @ts-ignore Argument of type 'Buffer' is not assignable to parameter of type 'Buffer'
// @ts-expect-error Argument of type 'Buffer' is not assignable to parameter of type 'Buffer'
const timeoutTimestamp = BitcoinJS.script.number.decode(BitcoinJS.Buffer.from(asm[++i], 'hex')) + (60 * 60);
if (asm[++i] !== 'OP_CHECKLOCKTIMEVERIFY' || asm[++i] !== 'OP_DROP') throw error;

Expand Down Expand Up @@ -164,7 +164,7 @@ class HtlcUtils { // eslint-disable-line no-unused-vars

writeVector(witness);

// @ts-ignore Type 'Buffer' is not assignable to type 'Buffer'.
// @ts-expect-error Type 'Buffer' is not assignable to type 'Buffer'.
return BitcoinJS.Buffer.from(buffer);
}
}
2 changes: 1 addition & 1 deletion src/request/sign-btc-transaction/SignBtcTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class SignBtcTransaction {
const psbt = new BitcoinJS.Psbt({ network: BitcoinUtils.Network });

// Add inputs
// @ts-ignore Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
psbt.addInputs(request.inputs);
// Add outputs
psbt.addOutputs(outputs);
Expand Down
3 changes: 1 addition & 2 deletions src/request/sign-btc-transaction/SignBtcTransactionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class SignBtcTransactionApi extends BitcoinRequestParserMixin(TopLevelApi) {
if (!layout) {
return SignBtcTransactionApi.Layouts.STANDARD;
}
// @ts-ignore (Property 'values' does not exist on type 'ObjectConstructor'.)
if (Object.values(SignBtcTransactionApi.Layouts).indexOf(layout) === -1) {
if (!Object.values(SignBtcTransactionApi.Layouts).includes(/** @type {any} */ (layout))) {
throw new Errors.InvalidRequestError('Invalid selected layout');
}
return /** @type KeyguardRequest.SignBtcTransactionRequestLayout */ (layout);
Expand Down
2 changes: 0 additions & 2 deletions src/request/sign-message/SignMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ class SignMessage {
const $tabWidthSelector = /** @type {HTMLDivElement} */ ($page.querySelector('#tab-width-selector'));
const tws = new TabWidthSelector($tabWidthSelector);

// @ts-ignore Property 'tabSize' does not exist on type 'CSSStyleDeclaration'
$message.style.tabSize = tws.width;

tws.on(TabWidthSelector.Events.INPUT, width => {
// @ts-ignore Property 'tabSize' does not exist on type 'CSSStyleDeclaration'
$message.style.tabSize = width;
});

Expand Down
3 changes: 1 addition & 2 deletions src/request/sign-swap/SignSwapApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ class SignSwapApi extends PolygonRequestParserMixin(BitcoinRequestParserMixin(To
if (!layout) {
return SignSwapApi.Layouts.STANDARD;
}
// @ts-ignore (Property 'values' does not exist on type 'ObjectConstructor'.)
if (Object.values(SignSwapApi.Layouts).indexOf(layout) === -1) {
if (!Object.values(SignSwapApi.Layouts).includes(/** @type {any} */ (layout))) {
throw new Errors.InvalidRequestError('Invalid selected layout');
}
return /** @type KeyguardRequest.SignSwapRequestLayout */ (layout);
Expand Down
3 changes: 1 addition & 2 deletions src/request/sign-transaction/SignTransactionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class SignTransactionApi extends TopLevelApi {
if (!layout) {
return SignTransactionApi.Layouts.STANDARD;
}
// @ts-ignore (Property 'values' does not exist on type 'ObjectConstructor'.)
if (Object.values(SignTransactionApi.Layouts).indexOf(layout) === -1) {
if (!Object.values(SignTransactionApi.Layouts).includes(/** @type {any} */ (layout))) {
throw new Errors.InvalidRequestError('Invalid selected layout');
}
return /** @type KeyguardRequest.SignTransactionRequestLayout */ (layout);
Expand Down
18 changes: 9 additions & 9 deletions src/request/swap-iframe/SwapIFrameApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
}

const htlcAddress = BitcoinJS.payments.p2wsh({
// @ts-ignore Type 'Uint8Array' is not assignable to type 'Buffer'.
// @ts-expect-error Type 'Uint8Array' is not assignable to type 'Buffer'.
witness: [BitcoinJS.Buffer.from(request.fund.htlcScript)],
network: BitcoinUtils.Network,
}).address;
Expand All @@ -205,7 +205,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
}

const outputScript = BitcoinJS.payments.p2wsh({
// @ts-ignore Type 'Uint8Array' is not assignable to type 'Buffer'.
// @ts-expect-error Type 'Uint8Array' is not assignable to type 'Buffer'.
witness: [BitcoinJS.Buffer.from(request.redeem.htlcScript)],
network: BitcoinUtils.Network,
}).output;
Expand Down Expand Up @@ -423,7 +423,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
const psbt = new BitcoinJS.Psbt({ network: BitcoinUtils.Network });

// Add inputs
// @ts-ignore Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
psbt.addInputs(inputs);
// Add outputs
psbt.addOutputs(outputs);
Expand All @@ -434,7 +434,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint

// Sign
const keyPairs = privateKeys.btc.map(privateKey => BitcoinJS.ECPair.fromPrivateKey(
// @ts-ignore Argument of type 'import("...").Buffer' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'import("...").Buffer' is not assignable to type 'Buffer'.
BitcoinJS.Buffer.from(privateKey, 'hex'),
));
for (const keyPair of keyPairs) {
Expand Down Expand Up @@ -468,7 +468,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint

const htlcAddress = parsedRequest.fund.htlcAddress;
const htlcScript = /** @type {Buffer} */ (BitcoinJS.payments.p2wsh({
// @ts-ignore Type 'import("...").Buffer' is not assignable to type 'Buffer'.
// @ts-expect-error Type 'import("...").Buffer' is not assignable to type 'Buffer'.
witness: [BitcoinJS.Buffer.from(parsedRequest.fund.htlcScript, 'hex')],
network: BitcoinUtils.Network,
}).output);
Expand All @@ -484,7 +484,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
script: htlcScript,
value: storedRequest.fund.recipientOutput.value,
},
// @ts-ignore Type of type 'import("...").Buffer' is not assignable to type 'Buffer'.
// @ts-expect-error Type of type 'import("...").Buffer' is not assignable to type 'Buffer'.
witnessScript: BitcoinJS.Buffer.from(parsedRequest.fund.htlcScript),
});

Expand All @@ -504,7 +504,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint

// Sign
const refundKeyPair = BitcoinJS.ECPair.fromPrivateKey(
// @ts-ignore Argument of type 'import("...").Buffer' is not assignable to parameter of
// @ts-expect-error Argument of type 'import("...").Buffer' is not assignable to parameter of
// type 'Buffer'.
BitcoinJS.Buffer.from(privateKeys.btc_refund, 'hex'),
);
Expand Down Expand Up @@ -643,14 +643,14 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
const psbt = new BitcoinJS.Psbt({ network: BitcoinUtils.Network });

// Add inputs
// @ts-ignore Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'Uint8Array' is not assignable to parameter of type 'Buffer'.
psbt.addInputs(inputs);
// Add outputs
psbt.addOutput(output);

// Sign
const keyPair = BitcoinJS.ECPair.fromPrivateKey(
// @ts-ignore Argument of type 'import("...").Buffer' is not assignable to parameter of type 'Buffer'.
// @ts-expect-error Argument of type 'import("...").Buffer' is not assignable to type 'Buffer'.
BitcoinJS.Buffer.from(privateKeys.btc[0], 'hex'),
);
psbt.signInput(0, keyPair);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
/* Basic Options */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"lib": ["DOM", "ES2020"], /* Specify library files to be included in the compilation. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["DOM"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down

0 comments on commit c415852

Please sign in to comment.