chrisrzhou / react-wordcloud

☁️ Simple React + D3 wordcloud component with powerful features.

Home Page:https://react-wordcloud.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Options not working in typescript

el-sacapuntas opened this issue · comments

 const options = {
        colors: ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b"],
        enableTooltip: true,
        deterministic: false,
        fontFamily: "impact",
        fontSizes: [5, 60],
        fontStyle: "normal",
        fontWeight: "normal",
        padding: 1,
        rotations: 3,
        rotationAngles: [0, 0],
        scale: "sqrt",
        spiral: "rectangular",
        transitionDuration: 1000
      };
    
    return (
        <Box>
        <ReactWordcloud
            words={words}
            options = {options}  // <- ERROR HERE
        />
        </Box>
    )

error:

Type '{ colors: string[]; enableTooltip: boolean; deterministic: boolean; fontFamily: string; fontSizes: number[]; fontStyle: string; fontWeight: string; padding: number; rotations: number; rotationAngles: number[]; scale: string; spiral: string; transitionDuration: number; }' is not assignable to type 'Optional<Options>'.
  Types of property 'fontSizes' are incompatible.
    Type 'number[]' is not assignable to type 'MinMaxPair'.
      Target requires 2 element(s) but source may have fewer.
The expected type comes from property 'options' which is declared here on type 'IntrinsicAttributes & Props'

you need to define options type.
you can write
const options:any = {
......
};