Skip to content

Commit a82ef47

Browse files
committed
fix(typescript): Fix typing, remove typeguard which would leave props: never afterwards
1 parent a6050a7 commit a82ef47

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/index.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import React from "react";
44
export type NextImageFromFileProps = Partial<ImageProps> &
55
Pick<ImageProps, "src">;
66

7-
function isImageProps(props: NextImageFromFileProps): props is ImageProps {
8-
return typeof props.src !== "string" || !!(props.width && props.height);
9-
}
10-
117
export default function NextImageFromFile(props: NextImageFromFileProps) {
128
const [image, setImage] = React.useState<null | {
139
width: number;
1410
height: number;
1511
}>(null);
1612

17-
if (isImageProps(props)) {
13+
// Fall back to regular next/image if all necessary props are given
14+
if (typeof props.src !== "string" || (props.width && props.height)) {
1815
return <Image {...props} unoptimized />;
1916
}
2017

18+
// No width and height available? Render raw img tag first to figure them out
2119
if (!image)
2220
return (
2321
<img
@@ -29,6 +27,7 @@ export default function NextImageFromFile(props: NextImageFromFileProps) {
2927
/>
3028
);
3129

30+
// Width and height have been figured out, render the next/image
3231
return (
3332
<Image
3433
{...props}

0 commit comments

Comments
 (0)