Definitelytyped: @types/react-css-modules: Property 'styleName' does not exist in type 'HTMLProps<HTMLElement>'

Created on 17 Oct 2016  路  9Comments  路  Source: DefinitelyTyped/DefinitelyTyped

Using the latest @types/react-css-modules: 3.7.4 with TypeScript 2.0.3 and React 15.3.2 results in unrecognized styleName property.

error TS2339: Property 'styleName' does not exist on type 'HTMLProps<HTMLElement>'.

I was using this custom definition and it worked fine before @types 2.0.

declare module 'react-css-modules' {
    interface Options {
        allowMultiple?: boolean;
        errorWhenNotFound?: boolean;
    }

    module Decorator {
        interface Props {
            styles?: any;
            styleName?: string;
        }
    }

    interface Decorator {
        (defaultStyles: any, options?: Options): any;
    }

    const Decorator: Decorator;

    export default Decorator;
}
@types

Most helpful comment

I have the same problem with @types/react-css-modules version 4.6.2

All 9 comments

@emzero being solved in #12184.

@emzero, merged, please close.

I have the same problem with @types/react-css-modules version 4.6.2

If anyone stumbles upon same error when using preact, add preact.d.ts file in your /types directory with following content:

import preact from 'preact';

declare global {
  namespace JSX {
    interface HTMLAttributes {
      styleName?: string;
    }

    interface SVGAttributes {
      styleName?: string;
    }
  }
}

@evenfrost
When I create a types/preact.d.ts file with that content I'm now getting the error

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

Any ideas? Is this overwriting an existing preact.d.ts file perhaps?

@JohnForster works good for me. Maybe some missing/misconfigured Preact-related typings?

An update for TypeScript 3.7:

// {project_root}/types/preact.d.ts
declare namespace preact {
  namespace JSX {
    interface HTMLAttributes {
      styleName?: string;
    }

    interface SVGAttributes {
      styleName?: string;
    }
  }
}

And in your tsconfig there should be proper compilerOptions.typeRoots property to catch up your declarations folder:

{
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/@types",
      "./types"
    ]
  }
}

This works for me.

// global.d.ts
import 'react';

declare module 'react' {
  interface Attributes {
    styleName?: string;
  }
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilling picture lilling  路  3Comments

jbreckmckye picture jbreckmckye  路  3Comments

csharpner picture csharpner  路  3Comments

alisabzevari picture alisabzevari  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments