ambassify / react-avatar

Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user.
MIT License
643 stars 117 forks source link

Type error with React 18 and TypeScript #258

Open Egor-Koldasov opened 1 year ago

Egor-Koldasov commented 1 year ago

Sample code

import ReactAvatar, { ConfigProvider } from "react-avatar";

const allowedColors: string[] = ["#ffffff", "#000000"];
export default function App() {
  return (
    <div className="App">
      <ConfigProvider colors={allowedColors}>
        <ReactAvatar name="Egor Koldasov" />
      </ConfigProvider>
    </div>
  );

ConfigProvider throws an error

Type '{ children: Element; colors: string[]; }' is not assignable to type 'IntrinsicAttributes & ConfigProvider'.
  Property 'children' does not exist on type 'IntrinsicAttributes & ConfigProvider'.

Sandbox example

https://codesandbox.io/s/heuristic-wing-jt95g8?file=/src/App.tsx

Example versions

"dependencies": {
    "react": "18.2.0",
    "react-avatar": "5.0.3",
    "react-dom": "18.2.0",
  },
  "devDependencies": {
    "@types/react": "18.0.25",
    "@types/react-dom": "18.0.9",
    "typescript": "4.4.2"
  },
hhoangg commented 1 year ago

I have the same problem

atefBB commented 1 year ago

@Egor-Koldasov did u manage to solve this issue ? any help will be appreciated !

okradze commented 11 months ago

I have same issue

renebigot commented 11 months ago

Same issue here

renebigot commented 11 months ago

For future readers : You can fix this lint error with a comment.

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <React.StrictMode>
    { /* @ts-expect-error : ConfigProvider has no children property in interface declaration */}
    <ConfigProvider colors={AVATAR_COLORS}>
      <App />
    </ConfigProvider>
  </React.StrictMode>
)
TannerJuby1 commented 2 months ago

@renebigot that is not a "fix", that is a workaround.