4

I created a default VS2017 react-redux template and tried to add material-ui-next component and I am getting following error:

ERROR in [at-loader] ./node_modules/material-ui/BottomNavigation/BottomNavigationButton.d.ts:6:74 TS2344: Type '"onChange"' does not satisfy the constraint '"className" | "style" | "component" | "classes" | "innerRef" | "centerRipple" | "disableRipple" |...'. 
ERROR in [at-loader] ./node_modules/material-ui/ButtonBase/ButtonBase.d.ts:6:13 TS2694: Namespace 'React' has no exported member 'AnchorHTMLAttributes'. 
ERROR in [at-loader] ./node_modules/material-ui/Snackbar/Snackbar.d.ts:10:18 TS2430: Interface 'SnackbarProps' incorrectly extends interface 'Pick<HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlers> & { classes: any; }, "defaultCh...'. Type 'SnackbarProps' is not assignable to type 'Pick<HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlers> & { classes: any; }, "defaultCh...'. Types of property 'action' are incompatible. Type 'ReactElement<any> | ReactElement<any>[]' is not assignable to type 'string'. Type 'ReactElement<any>' is not assignable to type 'string'.

This is my code:

```

import * as React from 'react';
import { Link, RouteComponentProps } from 'react-router-dom';
import { connect } from 'react-redux';
import { ApplicationState } from '../store';
import * as PetGiftboxProbabilitiesState from 
'../store/PetGiftboxProbabilities';
import { GridList, GridListTile } from 'material-ui/GridList';

// At runtime, Redux will merge together...
type PetGiftboxProbabilityProps =
PetGiftboxProbabilitiesState.PetGiftboxProbabilitiesState
& typeof PetGiftboxProbabilitiesState.actionCreators    
& RouteComponentProps<{}>;

class FetchData extends React.Component<PetGiftboxProbabilityProps, {}> {
componentWillMount() {
    // This method runs when the component is first added to the page
    this.props.requestPetGiftboxProbabilities();
}
public render() {
    return <div>
        <h1>Pet giftbox forecast</h1>
        {this.renderForecastsTable()}
    </div>;
}
private renderForecastsTable() {
    return <GridList cellHeight={160}>
        {this.props.petGiftboxProbabilities.map(pet =>
            <GridListTile key={pet.petId}>
                <img className="pet-image" src={pet.imageUrl} alt=
 {pet.petName} />
            </GridListTile>
        )}
    </GridList>;
 }
}

export default connect(
(state: ApplicationState) => state.PetGiftboxProbabilities,
PetGiftboxProbabilitiesState.actionCreators          
)(FetchData as any) as typeof FetchData;

What is wrong with my code? Thank you in advance.

2 Answers 2

1

Update 6/2/2018: I wouldn't recommend pinning to these old versions anymore. The latest versions of React types and material-ui should work together, although as of today there's a different typing issue with a fix pending that has a simple workaround: https://github.com/mui-org/material-ui/issues/11656

My current setup (next version of @material-ui/core should fix the issue caused by TS 2.9):

"@material-ui/core": "^1.1.0",
"@types/react": "^16.3.16",
"typescript": "^2.9.1"

I just had the same issue. An answer over in Type 'ReactType' is not generic (material-ui@next) pointed me in the right direction, but here are the specific packages and versions that I needed to update to:

"@types/react": "16.0.34",
"@types/react-dom": "16.0.34",
"@types/react-router": "4.2.0",
"@types/react-router-dom": "4.2.2",
"react": "16.0.34",
"react-dom": "16.0.34",
"react-router-dom": "4.2.2",

You could try updating those in package.json manually then running npm upgrade, or dropping node_modules and reinstalling. It ended up working for me, although it was a roundabout path of installing/upgrading/head banging for about 40 minutes before it finally compiled. I also recommend checking node_modules/@types/react/package.json to see which version is actually being used, if you run into trouble.

Sign up to request clarification or add additional context in comments.

Comments

0

npm upgrade worked for me - I started with yarn but quickly switched over when I moved to Material-UI-next.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.