Skip to content

Commit a6050a7

Browse files
committed
feat(typescript): prop type is Partial<ImageProps>
1 parent 27cd51f commit a6050a7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/index.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import Image, { ImageProps } from "next/image";
22
import React from "react";
33

4-
export default function NextImageFromFile(props: ImageProps) {
4+
export type NextImageFromFileProps = Partial<ImageProps> &
5+
Pick<ImageProps, "src">;
6+
7+
function isImageProps(props: NextImageFromFileProps): props is ImageProps {
8+
return typeof props.src !== "string" || !!(props.width && props.height);
9+
}
10+
11+
export default function NextImageFromFile(props: NextImageFromFileProps) {
512
const [image, setImage] = React.useState<null | {
613
width: number;
714
height: number;
815
}>(null);
916

10-
if (typeof props.src !== "string" || (props.width && props.height)) {
17+
if (isImageProps(props)) {
1118
return <Image {...props} unoptimized />;
1219
}
1320

0 commit comments

Comments
 (0)