-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageLoader: fix types and remove @ts-expect-error instances #1474
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Minor type fixes in the `ImageLoader` and `SvgImage` components |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ export type ImageProps = { | |
alt: string; | ||
title?: string; | ||
["aria-hidden"]?: boolean; | ||
tabIndex?: string; | ||
tabIndex?: number; | ||
onClick?: (e: React.SyntheticEvent) => void; | ||
style?: Dimensions; | ||
}; | ||
|
@@ -41,7 +41,7 @@ type Props = { | |
// When the DOM updates to replace the preloader with the image, or | ||
// vice-versa, we trigger this callback. | ||
onUpdate: (status: (typeof Status)[keyof typeof Status]) => void; | ||
preloader: () => React.ReactElement | null | undefined; | ||
preloader: (() => React.ReactNode) | null | undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main fix here is wrapping the function that returns a React element, otherwise it's a function that returns |
||
src: string; | ||
}; | ||
|
||
|
@@ -122,17 +122,15 @@ class ImageLoader extends React.Component<Props, State> { | |
|
||
renderImg: () => React.ReactElement<React.ComponentProps<"img">> = () => { | ||
const {src, imgProps} = this.props; | ||
let onKeyUp = null; | ||
let onKeyDown = null; | ||
let onKeyUp; | ||
let onKeyDown; | ||
if (imgProps.onClick != null) { | ||
// @ts-expect-error - TS2322 - Type '(e: React.KeyboardEvent) => void' is not assignable to type 'null'. | ||
onKeyUp = (e: React.KeyboardEvent) => { | ||
// 13 is enter key, 32 is space key | ||
if (e.keyCode === 13 || e.keyCode === 32) { | ||
imgProps.onClick && imgProps.onClick(e); | ||
} | ||
}; | ||
// @ts-expect-error - TS2322 - Type '(e: React.KeyboardEvent) => void' is not assignable to type 'null'. | ||
onKeyDown = (e: React.KeyboardEvent) => { | ||
// 32 is space key | ||
if (e.keyCode === 32) { | ||
|
@@ -146,9 +144,7 @@ class ImageLoader extends React.Component<Props, State> { | |
return ( | ||
<img | ||
src={staticUrl(src)} | ||
// @ts-expect-error - TS2322 - Type 'null' is not assignable to type 'KeyboardEventHandler<HTMLImageElement> | undefined'. | ||
onKeyUp={onKeyUp} | ||
// @ts-expect-error - TS2322 - Type 'null' is not assignable to type 'KeyboardEventHandler<HTMLImageElement> | undefined'. | ||
onKeyDown={onKeyDown} | ||
{...imgProps} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,6 @@ type SerializedState = { | |
hints: any; | ||
}; | ||
|
||
/* eslint-disable-next-line react/no-unsafe */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not actually suppressing anything so I'm removing it. |
||
export class ServerItemRenderer | ||
extends React.Component<Props, State> | ||
implements RendererInterface, KeypadContextRendererInterface | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type error was exposed once I removed the
@ts-expect-error
s.