Commit e9a69d14 authored by Robert Knight's avatar Robert Knight

Make src/shared/ typecheck when `noImplicitAny` is set

Fix various errors and omissions found when TypeScript's `noImplicitAny`
option is enabled.
parent 7d7ae510
......@@ -55,7 +55,7 @@ const PROTOCOL = 'frame-rpc';
*
* @param {MessagePort} port
* @param {string} method
* @param {any[]} [arguments]
* @param {any[]} [args]
* @param {number} [sequence] - Sequence number used for replies
*/
function sendCall(port, method, args = [], sequence = -1) {
......
......@@ -12,9 +12,9 @@ import { ConfirmModal } from '@hypothesis/frontend-shared';
* - The visual style of the dialog matches the Hypothesis design system
*
* @param {object} options - Options for the `ConfirmModal`
* @prop {string} [title]
* @prop {string} message
* @prop {string} [confirmAction]
* @param {string} [options.title]
* @param {string} options.message
* @param {string} [options.confirmAction]
* @return {Promise<boolean>} - Promise that resolves with `true` if the user
* confirmed the action or `false` if they canceled it.
*/
......
/** @param {number} val */
function byteToHex(val) {
const str = val.toString(16);
return str.length === 1 ? '0' + str : str;
......
......@@ -4,7 +4,7 @@ import { options } from 'preact';
* Setup workarounds for setting certain HTML element properties or attributes
* in some browsers.
*
* @param {object} _options - Test seam
* @param {import('preact').Options} _options - Test seam
*/
export function setupBrowserFixes(_options = options) {
let needsDirAutoFix = false;
......@@ -21,9 +21,10 @@ export function setupBrowserFixes(_options = options) {
const prevHook = _options.vnode;
_options.vnode = vnode => {
if (typeof vnode.type === 'string') {
if ('dir' in vnode.props && vnode.props.dir === 'auto') {
const props = /** @type {{ dir?: string }} */ (vnode.props);
if ('dir' in props && props.dir === 'auto') {
// Re-assign `vnode.props.dir` if its value is "auto"
vnode.props.dir = '';
props.dir = '';
}
}
// Call previously defined hook if there was any
......
......@@ -2,7 +2,11 @@ import { normalizeKeyName } from '@hypothesis/frontend-shared';
import { useEffect } from 'preact/hooks';
// Bit flags indicating modifiers required by a shortcut or pressed in a key event.
/**
* Bit flags indicating modifiers required by a shortcut or pressed in a key event.
*
* @type {Record<string, number>}
*/
const modifiers = {
alt: 1,
ctrl: 2,
......@@ -78,6 +82,7 @@ export function installShortcut(
onPress,
{ rootElement = document.body } = {}
) {
/** @param {KeyboardEvent} event */
const onKeydown = event => {
if (matchShortcut(event, shortcut)) {
onPress(event);
......
let shownWarnings = {};
/** @type {Set<string>} */
let shownWarnings = new Set();
/**
* Log a warning if it has not already been reported.
......@@ -13,13 +14,13 @@ let shownWarnings = {};
*/
export function warnOnce(...args) {
const key = args.join();
if (key in shownWarnings) {
if (shownWarnings.has(key)) {
return;
}
console.warn(...args);
shownWarnings[key] = true;
shownWarnings.add(key);
}
warnOnce.reset = () => {
shownWarnings = {};
shownWarnings.clear();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment