-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor: remove as casts from DamImageBlock #2911
base: main
Are you sure you want to change the base?
Conversation
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.
A better solution would be to change the generated block types to generate something like { type: "pixelImage"; props: PixelImageBlockData } | { type: "svgImage"; props: SvgImageBlockData }
@@ -11,10 +11,10 @@ const DamImageBlock = withPreview( | |||
return <PreviewSkeleton type="media" hasContent={false} aspectRatio={aspectRatio} />; | |||
} | |||
|
|||
if (block.type === "pixelImage") { | |||
return <PixelImageBlock data={block.props as PixelImageBlockData} aspectRatio={aspectRatio} {...imageProps} />; | |||
if (block.type === "pixelImage" && "cropArea" in block.props) { |
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 if presumably doesn't work if there's no crop area set in the PixelImageBlock, because then cropArea will be undefined: https://github.com/vivid-planet/comet/blob/main/packages/api/cms-api/src/dam/blocks/pixel-image-block-transformer.service.ts#L75
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.
You're right, I thought I checked, but it's indeed an optional field what about simply using urlTemplate
which is required instead?
I think there is no need for refactoring the object's structure, if the issue can be resolved by ts :)
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.
if (block.type === "pixelImage" && "urlTemplate" in block.props)
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.
urlTemplate is probably typed wrong. I believe it can be undefined. At least the block transformer service indicates that it is.
Description
Refactor the DamImageBlock site component to remove the hard casts (
as
) as they are error prone and unsafe.Simply use typescript to discriminate the union type with a sub-field of
PixelImageBlockData
Example
Changeset
Related tasks and documents
none