diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1773902de..b33215da0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `nested` glyph to `EuiIcon` ([#2707](https://github.com/elastic/eui/pull/2707)) - Added `tableLayout` prop to `EuiTable`, `EuiBasicTable` and `EuiInMemoryTable` to provide the option of auto layout ([#2697](https://github.com/elastic/eui/pull/2697)) +- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) **Bug fixes** diff --git a/src/components/error_boundary/__snapshots__/error_boundary.test.js.snap b/src/components/error_boundary/__snapshots__/error_boundary.test.tsx.snap similarity index 100% rename from src/components/error_boundary/__snapshots__/error_boundary.test.js.snap rename to src/components/error_boundary/__snapshots__/error_boundary.test.tsx.snap diff --git a/src/components/error_boundary/error_boundary.test.js b/src/components/error_boundary/error_boundary.test.tsx similarity index 100% rename from src/components/error_boundary/error_boundary.test.js rename to src/components/error_boundary/error_boundary.test.tsx diff --git a/src/components/error_boundary/error_boundary.js b/src/components/error_boundary/error_boundary.tsx similarity index 62% rename from src/components/error_boundary/error_boundary.js rename to src/components/error_boundary/error_boundary.tsx index c65452ecce9..8e00024215f 100644 --- a/src/components/error_boundary/error_boundary.js +++ b/src/components/error_boundary/error_boundary.tsx @@ -1,23 +1,37 @@ -import React, { Component } from 'react'; +import React, { Component, HTMLAttributes } from 'react'; +import { CommonProps } from '../common'; import PropTypes from 'prop-types'; import { EuiText } from '../text'; -export class EuiErrorBoundary extends Component { +interface EuiErrorBoundaryState { + hasError: boolean; + error?: Error; +} + +export type EuiErrorBoundaryProps = CommonProps & + HTMLAttributes; + +export class EuiErrorBoundary extends Component< + EuiErrorBoundaryProps, + EuiErrorBoundaryState +> { static propTypes = { children: PropTypes.node, }; - constructor(props) { + constructor(props: EuiErrorBoundaryProps) { super(props); - this.state = { + const errorState: EuiErrorBoundaryState = { hasError: false, error: undefined, }; + + this.state = errorState; } - componentDidCatch(error) { + componentDidCatch(error: Error) { // Display fallback UI this.setState({ hasError: true, diff --git a/src/components/error_boundary/index.d.ts b/src/components/error_boundary/index.d.ts deleted file mode 100644 index c2a9592bbca..00000000000 --- a/src/components/error_boundary/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { HTMLAttributes, Component } from 'react'; -import { CommonProps } from '../common'; - -declare module '@elastic/eui' { - // eslint-disable-next-line react/prefer-stateless-function - export class EuiErrorBoundary extends Component< - CommonProps & HTMLAttributes - > {} -} diff --git a/src/components/error_boundary/index.js b/src/components/error_boundary/index.js deleted file mode 100644 index ef3275c00f7..00000000000 --- a/src/components/error_boundary/index.js +++ /dev/null @@ -1 +0,0 @@ -export { EuiErrorBoundary } from './error_boundary'; diff --git a/src/components/error_boundary/index.ts b/src/components/error_boundary/index.ts new file mode 100644 index 00000000000..17078e25e9c --- /dev/null +++ b/src/components/error_boundary/index.ts @@ -0,0 +1 @@ +export { EuiErrorBoundary, EuiErrorBoundaryProps } from './error_boundary'; diff --git a/src/components/index.d.ts b/src/components/index.d.ts index 3db682a3c7d..0841f75163c 100644 --- a/src/components/index.d.ts +++ b/src/components/index.d.ts @@ -1,7 +1,6 @@ /// /// /// -/// /// /// ///