mikbry / mui-color

Preview of Material-UI-color picker port to Mui v5
MIT License
34 stars 23 forks source link

Property 'hex' does not exist on type 'ColorValue'. #6

Open egazarian opened 2 years ago

egazarian commented 2 years ago

Version

typescript: 4.1.2 mui-color: 2.0.0-beta.2 @mui/material: 5.0.4 react: 17.0.2 @emotion/react: 11.5.0 @emotion/styled: 11.3.0

Issue

When trying to access to the hex value of a ColorValue inside of ColorPicker onChange event handler, typescript throw Property 'hex' does not exist on type 'ColorValue'. Same issue for all the properties of ColorValue object.

Screenshot

Capture d’écran 2022-04-14 à 10 16 19

Workaround

<ColorPicker
    onChange={(e) => {
        const color = e as ColorObject;
        console.log(color.hex);
    }}
/>

Should the onChange handler argument type be ColorObject instead of ColorValue ?

Briimbo commented 2 years ago

I don't think this is a bug. You can also enter text in the color picker to get a color. The argument type used to be Color though instead of ColorValue grafik

egazarian commented 2 years ago

Ok, I got it. And yes, it would be better to have an argument of type Color, instead of ColorValue. In this way we should be able to get the color as any format.