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'; ...@@ -55,7 +55,7 @@ const PROTOCOL = 'frame-rpc';
* *
* @param {MessagePort} port * @param {MessagePort} port
* @param {string} method * @param {string} method
* @param {any[]} [arguments] * @param {any[]} [args]
* @param {number} [sequence] - Sequence number used for replies * @param {number} [sequence] - Sequence number used for replies
*/ */
function sendCall(port, method, args = [], sequence = -1) { function sendCall(port, method, args = [], sequence = -1) {
......
...@@ -12,9 +12,9 @@ import { ConfirmModal } from '@hypothesis/frontend-shared'; ...@@ -12,9 +12,9 @@ import { ConfirmModal } from '@hypothesis/frontend-shared';
* - The visual style of the dialog matches the Hypothesis design system * - The visual style of the dialog matches the Hypothesis design system
* *
* @param {object} options - Options for the `ConfirmModal` * @param {object} options - Options for the `ConfirmModal`
* @prop {string} [title] * @param {string} [options.title]
* @prop {string} message * @param {string} options.message
* @prop {string} [confirmAction] * @param {string} [options.confirmAction]
* @return {Promise<boolean>} - Promise that resolves with `true` if the user * @return {Promise<boolean>} - Promise that resolves with `true` if the user
* confirmed the action or `false` if they canceled it. * confirmed the action or `false` if they canceled it.
*/ */
......
/** @param {number} val */
function byteToHex(val) { function byteToHex(val) {
const str = val.toString(16); const str = val.toString(16);
return str.length === 1 ? '0' + str : str; return str.length === 1 ? '0' + str : str;
......
...@@ -4,7 +4,7 @@ import { options } from 'preact'; ...@@ -4,7 +4,7 @@ import { options } from 'preact';
* Setup workarounds for setting certain HTML element properties or attributes * Setup workarounds for setting certain HTML element properties or attributes
* in some browsers. * in some browsers.
* *
* @param {object} _options - Test seam * @param {import('preact').Options} _options - Test seam
*/ */
export function setupBrowserFixes(_options = options) { export function setupBrowserFixes(_options = options) {
let needsDirAutoFix = false; let needsDirAutoFix = false;
...@@ -21,9 +21,10 @@ export function setupBrowserFixes(_options = options) { ...@@ -21,9 +21,10 @@ export function setupBrowserFixes(_options = options) {
const prevHook = _options.vnode; const prevHook = _options.vnode;
_options.vnode = vnode => { _options.vnode = vnode => {
if (typeof vnode.type === 'string') { 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" // Re-assign `vnode.props.dir` if its value is "auto"
vnode.props.dir = ''; props.dir = '';
} }
} }
// Call previously defined hook if there was any // Call previously defined hook if there was any
......
...@@ -2,7 +2,11 @@ import { normalizeKeyName } from '@hypothesis/frontend-shared'; ...@@ -2,7 +2,11 @@ import { normalizeKeyName } from '@hypothesis/frontend-shared';
import { useEffect } from 'preact/hooks'; 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 = { const modifiers = {
alt: 1, alt: 1,
ctrl: 2, ctrl: 2,
...@@ -78,6 +82,7 @@ export function installShortcut( ...@@ -78,6 +82,7 @@ export function installShortcut(
onPress, onPress,
{ rootElement = document.body } = {} { rootElement = document.body } = {}
) { ) {
/** @param {KeyboardEvent} event */
const onKeydown = event => { const onKeydown = event => {
if (matchShortcut(event, shortcut)) { if (matchShortcut(event, shortcut)) {
onPress(event); onPress(event);
......
let shownWarnings = {}; /** @type {Set<string>} */
let shownWarnings = new Set();
/** /**
* Log a warning if it has not already been reported. * Log a warning if it has not already been reported.
...@@ -13,13 +14,13 @@ let shownWarnings = {}; ...@@ -13,13 +14,13 @@ let shownWarnings = {};
*/ */
export function warnOnce(...args) { export function warnOnce(...args) {
const key = args.join(); const key = args.join();
if (key in shownWarnings) { if (shownWarnings.has(key)) {
return; return;
} }
console.warn(...args); console.warn(...args);
shownWarnings[key] = true; shownWarnings.add(key);
} }
warnOnce.reset = () => { 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