Skip to content

Typescript decorator typing errors for custom params on a class component #74

Closed
@OscarBarrett

Description

@OscarBarrett

When using the @themr decorator on a React class component, if there are custom parameters (such as a parameter holding a ref) then Typescript gives the following error:

Unable to resolve signature of class decorator when called as an expression.
  Type 'ThemedComponentClass<{ mapThemrProps?: TMapThemrProps<{}>; }, {}>' is not assignable to type 'typeof App'.
    Property 'myRef' is missing in type 'ThemedComponent<{ mapThemrProps?: TMapThemrProps<{}>; }, {}>' but required in type 'App'.ts(1238)

Simple example here: https://codesandbox.io/s/flamboyant-wiles-bu7m3

import * as React from "react";
import { render } from "react-dom";
import { themr } from "@friendsofreactjs/react-css-themr";

const styles = require("./styles.css");

@themr("App", styles)
export default class App extends React.Component {
  myRef: any = React.createRef();

  render() {
    return (
      <div className="foo" ref={this.myRef}>
        Foo
      </div>
    );
  }
}

const rootElement = document.getElementById("root");
render(<App />, rootElement);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions