Skip to content

Props as types instead of interfaces are not supported #21

@forabi

Description

@forabi

This example is based on the one in this project.

How to reproduce?

Add new file, FlippableImage.tsx:

import * as React from 'react';

export interface Props extends React.HTMLAttributes<HTMLImageElement> {
  /** whether the image is flipped horizontally */
  isFlippedX?: boolean;
  /** whether the image is flipped vertically */
  isFlippedY?: boolean;
}

/** An enhanced image component */
export const FlippableImage = (props: Props) => {
  const {
    src,
    isFlippedX = false,
    isFlippedY = false,
    style,
    ...rest,
  } = props;

  let transform = '';
  if (isFlippedX) {
    transform += ` scale(-1, 1)`;
  }
  if (isFlippedY) {
    transform += ` scale(1, -1)`;
  }

  return (
    <img
      src={src || undefined}
      style={{ ...style, transform }}
      {...rest}
    />
  );
};

export default FlippableImage;

This works as intended. However, when using type instead of interface, like this:

export type Props = React.HTMLAttributes<HTMLImageElement> & {
  /** whether the image is flipped horizontally */
  isFlippedX?: boolean;
  /** whether the image is flipped vertically */
  isFlippedY?: boolean;
}

I get the following error:

Error in ./components/FlippableImage.tsx
Module build failed: TypeError: Cannot read property 'methods' of null
 @ ./~/react-styleguidist/loaders/styleguide-loader.js!./~/react-styleguidist/lib/index.js 26:29-276
 @ ./~/react-styleguidist/lib/index.js
 @ multi ./~/react-styleguidist/lib/index ./~/react-dev-utils/webpackHotDevClient.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions