Skip to content

Commit c896006

Browse files
authored
refactor: enable isolated declarations for image package (#4500)
React components need to be annotated with ForwardRefExoticComponent until we migrate to react v19
1 parent dad162c commit c896006

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

packages/image/src/image-dev.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { Image as ImagePrimitive, createImageLoader } from "./";
99
// @ts-ignore
1010
import localLogoImage from "../storybook-assets/logo.webp";
1111

12-
export default {
12+
const meta: Meta<typeof ImagePrimitive> = {
1313
title: "Components/ImageDev",
14-
} satisfies Meta<typeof ImagePrimitive>;
14+
};
15+
export default meta;
1516

1617
type ImageProps = React.ComponentProps<typeof ImagePrimitive>;
1718

packages/image/src/image-optimize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type ImageLoader = (
104104
const imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
105105
const deviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
106106

107-
export const allSizes = [...imageSizes, ...deviceSizes];
107+
export const allSizes: number[] = [...imageSizes, ...deviceSizes];
108108

109109
/**
110110
* https://github.com/vercel/next.js/blob/canary/packages/next/client/image.tsx
@@ -235,7 +235,7 @@ const DEFAULT_QUALITY = 80;
235235
/**
236236
* URL.canParse(props.src)
237237
*/
238-
export const UrlCanParse = (url: string) => {
238+
export const UrlCanParse = (url: string): boolean => {
239239
try {
240240
new URL(url);
241241
return true;

packages/image/src/image.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { forwardRef, type ElementRef, type ComponentProps } from "react";
1+
import {
2+
forwardRef,
3+
type ComponentProps,
4+
type ForwardRefExoticComponent,
5+
} from "react";
26
import { getImageAttributes, type ImageLoader } from "./image-optimize";
37

48
const defaultTag = "img";
@@ -9,7 +13,7 @@ type ImageProps = ComponentProps<typeof defaultTag> & {
913
loader: ImageLoader;
1014
};
1115

12-
export const Image = forwardRef<ElementRef<typeof defaultTag>, ImageProps>(
16+
export const Image: ForwardRefExoticComponent<ImageProps> = forwardRef(
1317
(
1418
{
1519
quality,
@@ -46,7 +50,7 @@ export const Image = forwardRef<ElementRef<typeof defaultTag>, ImageProps>(
4650

4751
Image.displayName = "Image";
4852

49-
export const imagePlaceholderDataUrl = `data:image/svg+xml;base64,${btoa(`<svg
53+
export const imagePlaceholderDataUrl: string = `data:image/svg+xml;base64,${btoa(`<svg
5054
width="140"
5155
height="140"
5256
viewBox="0 0 600 600"

packages/image/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@webstudio-is/tsconfig/base.json"
2+
"extends": "@webstudio-is/tsconfig/base.json",
3+
"compilerOptions": {
4+
"isolatedDeclarations": true
5+
}
36
}

0 commit comments

Comments
 (0)