Patternfly-react: PatternFly 4: Could not find a declaration file for module '@patternfly/react-styles'

Created on 2 Nov 2018  路  5Comments  路  Source: patternfly/patternfly-react

Hello,

I'm trying to develop an app with patternfly-react + typescript, using typescript-react-starter. As soon as I add a Button with the first Hello component, I get the following error while building it:

/home/tasato/projects/my-app/node_modules/@patternfly/react-core/dist/js/styles/gutters.d.ts
(1,53): Could not find a declaration file for module '@patternfly/react-styles'. '/home/tasato/projects/my-app/node_modules/@patternfly/react-styles/dist/js/index.js' implicitly has an 'any' type.
  Try `npm install @types/patternfly__react-styles` if it exists or add a new declaration (.d.ts) file containing `declare module '@patternfly/react-styles';`

Any ideas why it happens and how I can resolve it?

Here is my Hello.tsx:

import { Button } from '@patternfly/react-core';
import * as React from 'react';
import './Hello.css';
export interface IProps {
  name: string;
}
class Hello extends React.Component<IProps, object> {
  public render() {
    const { name } = this.props;
    return (
      <div className="hello">
        <div className="greeting">
          Hello {name}!
        </div>
        <Button variant="primary">Button</Button>
      </div>
    );
  }
}
export default Hello;
PF4 bug infrastructure p1

All 5 comments

I'm having the same issue. I've checked out this project and found out that the required index.d.ts for react-styles is present under src/ but it's not transferred into dist/ during build.

So my guess is this might be a build configuration problem but I don't know the build system yet (is it done by Babel?) so I can't fix it. I could try that with some guidance or I can provide a minimal reproducing project if that helps.

OK, so at least adding noImplicitAny: false in tsconfig.json works around the issue (thanks to @danielefiungo).

But it's still ideal to work without allowing implicit any.

@rachael-phillips - can we get this prioritized?

Yes, I'll add this to sprint planning. Thanks @dgutride !

Was this page helpful?
0 / 5 - 0 ratings