chatscope / chat-ui-kit-react

Build your own chat UI with React components in few minutes. Chat UI Kit from chatscope is an open source UI toolkit for developing web chat applications.
https://chatscope.io
MIT License
1.34k stars 116 forks source link

`Property 'as' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'` #99

Closed jimmykane closed 9 months ago

jimmykane commented 1 year ago

Example from recipeis

<div as={MessageInput}>
          <MessageInput />
          <button>Custom button</button>
        </div>

Typescript

Property 'as' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

aledeloss commented 1 year ago

Hi! I am having the same issue here, any comments of fixes on this? Thank you!

supersnager commented 1 year ago

@jimmykane @aledeloss There are two ways to fix it.

  1. You can augment the 'react' module and add the as attribute:
    declare module 'react' {
    interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
        as?: string | typeof MessageInput;
    }
    }

or

  1. Wrap the div with an additional component that has the as property:
interface ExtentedInputProps extends MessageInputProps {
    as?: string | typeof MessageInput;
}

const ExtendedInput = (props:ExtentedInputProps) => {
    return (
        <div>
            <span>Custom content</span>
            <MessageInput />
        </div>
    );
}

<ChatContainer>
  <MessageList></MessageList>
  <ExtendedInput as={MessageInput} />
</ChatContainer>
supersnager commented 1 year ago

I have added this explanation to the documentation: https://chatscope.io/storybook/react/?path=/docs/documentation-recipes--page#what-about-typescript

jimmykane commented 1 year ago

Thank you !

On Fri, 19 May 2023, 10:29 am Super Snager, @.***> wrote:

I have added this explanation to the documentation:

https://chatscope.io/storybook/react/?path=/docs/documentation-recipes--page#what-about-typescript

— Reply to this email directly, view it on GitHub https://github.com/chatscope/chat-ui-kit-react/issues/99#issuecomment-1554162870, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVX4YPJTNIVSNS3SVRSOTXG4OMXANCNFSM6AAAAAAXK7AYOM . You are receiving this because you were mentioned.Message ID: @.***>