'React using TypeScript, Don't use {} as a type. {

I am getting an ESlint error Don't use `{}` as a type. `{}` actually means "any non-nullish value". in my Contact component whiling using React and TypeScript.

The component doesn't have any props.

export default class Contact extends React.Component<{}, MyState> {
    constructor(props = {}) {
        super(props);
        this.state = {
            signedUp: false,
        };
    }
}

I tried using null instead, but that threw other ESLint errors.



Solution 1:[1]

Expanding on Jordan answer to apply this rule to only React components in the .eslintrc.js file add

overrides: [
    {
        files: ['*.tsx, *.jsx'],
        rules: {
            '@typescript-eslint/ban-types': [
                'error',
                {
                    extendDefaults: true,
                    types: {
                        '{}': false,
                    },
                },
            ],
        },
    },
]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lboyel