Skip to content

Argument of type 'ForwardRefExoticComponent<Props & RefAttributes<HTMLAnchorElement>>' is not assignable to parameter of type 'ComponentType<{ className: string; link: LinkControlValue<_T>; #506

Description

@jasdeepg

Attempting to register blog components in Makeswift but getting a not assignable error when trying to build.

Type error: Argument of type 'ForwardRefExoticComponent<Props & RefAttributes<HTMLAnchorElement>>' is not assignable to parameter of type 'ComponentType<{ className: string; link: LinkControlValue<_T>; orientation: "horizontal" | "vertical" | undefined; image: ReactNode; preHeading: string; heading: string; body: string; date: string; readtime: number; }>'.
  Type 'ForwardRefExoticComponent<Props & RefAttributes<HTMLAnchorElement>>' is not assignable to type '(props: { className: string; link: LinkControlValue<_T>; orientation: "horizontal" | "vertical" | undefined; image: ReactNode; preHeading: string; heading: string; body: string; date: string; readtime: number; } & RefAttributes<...>, context?: any) => ReactElement<...> | null'.
    Types of parameters 'props' and 'props' are incompatible.
      Type '{ className: string; link: LinkControlValue<_T>; orientation: "horizontal" | "vertical" | undefined; image: ReactNode; preHeading: string; heading: string; body: string; date: string; readtime: number; } & RefAttributes<...>' is not assignable to type 'Props & RefAttributes<HTMLAnchorElement>'.
        Type '{ className: string; link: LinkControlValue<_T>; orientation: "horizontal" | "vertical" | undefined; image: ReactNode; preHeading: string; heading: string; body: string; date: string; readtime: number; } & RefAttributes<...>' is not assignable to type 'Props'.
          Types of property 'image' are incompatible.
            Type 'import("/Users/jasdeepg/Library/CloudStorage/Dropbox/workspace/scaletech/schematic-marketing-website/node_modules/@makeswift/runtime/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
              Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
                Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.

   9 |
  10 |
> 11 | runtime.registerComponent(Post,
     |                           ^
  12 |   {
  13 |     type: 'Post',
  14 |     label: 'Post',

Trying to follow example here: https://github.com/makeswift/transcend-io

Here's the Post.makeswift file contents

import dynamic from 'next/dynamic'

import { Link, Number, Select, Slot, Style, TextInput } from '@makeswift/runtime/controls'
import { forwardNextDynamicRef } from '@makeswift/runtime/next'

import { runtime } from '@/lib/makeswift/runtime'

import { Post } from '@/components/Post/Post'


runtime.registerComponent(Post,
  {
    type: 'Post',
    label: 'Post',
    props: {
      className: Style(),
      link: Link(),
      orientation: Select({
        label: 'Orientation',
        options: [
          { label: 'Horizontal', value: 'horizontal' },
          { label: 'Vertical', value: 'vertical' },
        ],
      }),
      image: Slot(),
      preHeading: TextInput({
        label: 'Pre heading',
        defaultValue: 'Featured Post',
      }),
      heading: TextInput({
        label: 'Heading',
        defaultValue: 'How to make a website',
      }),
      body: TextInput({
        label: 'Body',
        defaultValue:
          "Learn how to make a website with this easy to follow tutorial. We'll walk you through step by step.",
      }),
      date: TextInput({
        label: 'Date',
        defaultValue: 'May 31, 2023',
      }),
      readtime: Number({
        label: 'Read time',
        defaultValue: 5,
        suffix: 'min read',
      }),
    },
  },
)

/*
forwardNextDynamicRef(patch => dynamic(() => patch(import('./Post').then(({ Post }) => Post))))*/

and the Post.tsx file contents

import Link from 'next/link'
import { Ref, forwardRef } from 'react'

import clsx from 'clsx'

type Props = {
  className?: string
  link?: { href: string; target?: '_blank' | '_self' }
  orientation?: 'horizontal' | 'vertical'
  image?: React.ReactNode  
  preHeading?: string | null
  heading?: string | null
  body?: string | null
  date?: string | null
  readtime?: number | null
}

export const Post = forwardRef(function Post(
  {
    className,
    link,
    orientation,
    image,
    preHeading,
    heading,
    body,
    date,
    readtime,
  }: Props,
  ref: Ref<HTMLAnchorElement>,
) {
  return (
    <Link
      ref={ref}
      href={link?.href ?? '#'}
      target={link?.target}
      className={clsx(
        className,
        'group',
        {
          horizontal: 'grid grid-cols-12 gap-y-5 md:gap-x-16 md:gap-y-0',
          vertical: 'space-y-5',
        }[orientation],
      )}
    >
      <div
        className={clsx(
          'relative',
          {
            horizontal: 'col-span-12 h-[300px] md:col-span-6 md:h-[400px]',
            vertical: 'col-span-12 h-[250px]',
          }[orientation],
        )}
      >
        {image}
      </div>
      <div
        className={clsx(
          'space-y-5 py-5',
          {
            horizontal: 'col-span-12 md:col-span-6',
            vertical: 'col-span-12',
          }[orientation],
        )}
      >
        <div className="text-xs font-bold uppercase text-blue-100">{preHeading}</div>
        <h3 className="text-3xl font-bold group-hover:text-blue-100">{heading}</h3>
        <p className="text-lg font-light">{body}</p>
        <p className="text-base text-gray-500">
          {date &&
            `${new Date(date).toLocaleDateString('en-US', {
              month: 'long',
              day: 'numeric',
              year: 'numeric',
            })} • `}
          {readtime && `${readtime} min read`}
        </p>
      </div>
    </Link>
  )
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions