Реагирует с ошибками выбрасывания Стилей при использовании 'direction' - PullRequest
0 голосов
/ 28 июня 2019

У меня простой веб-сайт React, и я использую функцию withStyles для передачи стилей элементу grid-ui material-ui.При попытке использовать direction: "column" в стиле я получаю сообщение об ошибке, приведенное ниже.

Это файл .jsx.Я нашел исправление, указав тип, но это работает только для TypeScript.

Вот файл App.jsx:


const styles = theme => ({
    root: {
        direction: "column",
        justify: "center",
        alignItems: "center",
    },
});

function App(props) {

    return (
        <div>
            <Grid container className={props.classes.root} >
                <Typography variant="h2">
                    Test Website
                </Typography>
                <TextField
                    id="input-user"
                    label="User"
                    value={1}
                    margin="normal"
                    variant="outlined"
                />

            </Grid>
        </div>
    )

}

export default withStyles(styles)(App);

Я получаю следующее сообщение об ошибке:

Argument of type '(theme: any) => { root: { direction: string; justify: string; alignItems: string; }; }' is not assignable to parameter of type 'Styles<Theme, {}, "root">'.
  Type '(theme: any) => { root: { direction: string; justify: string; alignItems: string; }; }' is not assignable to type 'StyleRulesCallback<Theme, {}, "root">'.
    Type '{ root: { direction: string; justify: string; alignItems: string; }; }' is not assignable to type 'Record<"root", CreateCSSProperties<{}> | ((props: {}) => CreateCSSProperties<{}>)>'.
      Types of property 'root' are incompatible.
        Type '{ direction: string; justify: string; alignItems: string; }' is not assignable to type 'CreateCSSProperties<{}> | ((props: {}) => CreateCSSProperties<{}>)'.
          Type '{ direction: string; justify: string; alignItems: string; }' is not assignable to type 'CreateCSSProperties<{}>'.
            Types of property 'direction' are incompatible.
              Type 'string' is not assignable to type '"-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "ltr" | "rtl" | ((props: {}) => DirectionProperty)'.

Спасибо за любую помощь.

1 Ответ

1 голос
/ 28 июня 2019

это потому, что в свойстве direction нет типа column. может принимать строку типа:

  • буква
  • РТЛ
  • начальный
  • 1012 * унаследуют *
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...