Skip to content

Commit 545239d

Browse files
dhruvikpatel18dhruvikpatel18manzoorwanijk
authored andcommitted
Migrate plugins package to TS (WordPress#70773)
Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
1 parent 7889b63 commit 545239d

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

packages/plugins/src/components/plugin-error-boundary/index.js renamed to packages/plugins/src/components/plugin-error-boundary/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,34 @@
33
*/
44
import { Component } from '@wordpress/element';
55

6-
export class PluginErrorBoundary extends Component {
7-
/**
8-
* @param {Object} props
9-
*/
10-
constructor( props ) {
6+
/**
7+
* Internal dependencies
8+
*/
9+
import type {
10+
PluginErrorBoundaryProps as Props,
11+
PluginErrorBoundaryState as State,
12+
} from '../../types';
13+
14+
export class PluginErrorBoundary extends Component< Props, State > {
15+
constructor( props: Props ) {
1116
super( props );
1217
this.state = {
1318
hasError: false,
1419
};
1520
}
1621

17-
static getDerivedStateFromError() {
22+
static getDerivedStateFromError(): State {
1823
return { hasError: true };
1924
}
2025

21-
/**
22-
* @param {Error} error Error object passed by React.
23-
*/
24-
componentDidCatch( error ) {
26+
componentDidCatch( error: Error ): void {
2527
const { name, onError } = this.props;
2628
if ( onError ) {
2729
onError( name, error );
2830
}
2931
}
3032

31-
render() {
33+
render(): React.ReactNode {
3234
if ( ! this.state.hasError ) {
3335
return this.props.children;
3436
}
File renamed without changes.

packages/plugins/src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Props for the PluginErrorBoundary component.
3+
*/
4+
export interface PluginErrorBoundaryProps {
5+
/**
6+
* The name of the plugin that may encounter an error.
7+
*/
8+
name: string;
9+
/**
10+
* The child components to render.
11+
*/
12+
children: React.ReactNode;
13+
/**
14+
* Callback function called when an error occurs.
15+
*/
16+
onError?: ( name: string, error: Error ) => void;
17+
}
18+
19+
/**
20+
* State for the PluginErrorBoundary component.
21+
*/
22+
export interface PluginErrorBoundaryState {
23+
hasError: boolean;
24+
}

0 commit comments

Comments
 (0)