11import { Alert , GetProps } from 'antd' ;
22import { AlertRef } from 'antd/es/alert/Alert' ;
33import { ComponentToken as AlertComponentTokenAntd } from 'antd/es/drawer/style' ;
4- import { ComponentProps } from 'react' ;
4+ import React , { ComponentProps } from 'react' ;
55
66type AlertPropsAntd = GetProps < typeof Alert > ;
7- type AlertErrorBoundaryPropsAntd = GetProps < typeof Alert . ErrorBoundary > ;
87
8+ /**
9+ * 📝 Explanation:
10+ *
11+ * For most Ant Design components, we can simply get the props type using:
12+ * type XxxPropsAntd = GetProps<typeof Xxx>;
13+ *
14+ * However, `Alert.ErrorBoundary` is a special case:
15+ * - Ant Design does NOT export a public props interface for ErrorBoundary.
16+ * - If we directly use `GetProps<typeof Alert.ErrorBoundary>`,
17+ * TypeScript will try to expose internal types and throw an error:
18+ * ts(4023): "Exported variable '...' has or is using name '...' but cannot be named".
19+ *
20+ * 🚑 Workaround:
21+ * - Use `ComponentProps<typeof Alert.ErrorBoundary>` to get the props,
22+ * then clone it via a mapped type to produce a "public" type.
23+ * - This way we avoid referencing Ant Design’s internal types.
24+ *
25+ * 🔮 Note:
26+ * - If Ant Design exports a proper `AlertErrorBoundaryProps` type in the future,
27+ * we can safely remove this workaround and write:
28+ * type AlertErrorBoundaryPropsAntd = GetProps<typeof Alert.ErrorBoundary>;
29+ */
30+ type AlertErrorBoundaryPropsAntd = {
31+ [ K in keyof ComponentProps < typeof Alert . ErrorBoundary > ] : ComponentProps <
32+ typeof Alert . ErrorBoundary
33+ > [ K ] ;
34+ } ;
35+
36+ /**
37+ * 📝 Explanation:
38+ *
39+ * Ant Design also does not export the `ErrorBoundaryStates` type.
40+ * Therefore, instead of extracting it automatically, we need to define this interface manually.
41+ *
42+ * The state shape is referenced from the source code:
43+ * state: {
44+ * error: undefined;
45+ * info: {
46+ * componentStack: string;
47+ * };
48+ * }
49+ *
50+ * This is simply a copied definition to ensure type safety for our extended components.
51+ * If Ant Design exports `ErrorBoundaryStates` in the future, we should switch to that instead.
52+ */
53+ interface AlertErrorBoundaryStatesAntd {
54+ error ?: Error | null ;
55+ info ?: {
56+ componentStack ?: string ;
57+ } ;
58+ }
959type AlertRefAntd = AlertRef ;
1060
1161//#endregion
@@ -17,24 +67,34 @@ type AlertComponentTokenExtend = {};
1767//#region Define extended types
1868type AlertPropsExtend = { } ;
1969type AlertErrorBoundaryPropsExtend = { } ;
70+ type AlertErrorBoundaryStatesExtend = { } ;
2071
2172type AlertRefExtend = { } ;
2273//#endregion
2374
2475//#region Export types
2576export type RdAlertProps = AlertPropsAntd & AlertPropsExtend ;
2677export type RdAlertErrorBoundaryProps = AlertErrorBoundaryPropsAntd & AlertErrorBoundaryPropsExtend ;
78+ export type RdAlertErrorBoundaryStates = AlertErrorBoundaryStatesAntd &
79+ AlertErrorBoundaryStatesExtend ;
2780export type RdAlertRef = AlertRefAntd & AlertRefExtend ;
2881export type RdAlertComponentToken = AlertComponentTokenAntd & AlertComponentTokenExtend ;
2982//#endregion
3083
3184//#region Define component types
32- // export type RdAlertComponent = React.FC<RdAlertProps>;
3385export type RdAlertComponent = React . ForwardRefExoticComponent <
3486 RdAlertProps & React . RefAttributes < RdAlertRef >
3587> ;
88+ export declare class RdAlertErrorBoundaryComponent extends React . Component <
89+ RdAlertErrorBoundaryProps ,
90+ RdAlertErrorBoundaryStates
91+ > {
92+ state : RdAlertErrorBoundaryStates ;
93+ componentDidCatch ( error : Error | null , info : object ) : void ;
94+ render ( ) : React . ReactNode ;
95+ }
3696
3797export type RdAlertCompoundedComponent = RdAlertComponent & {
38- // Timer: RdAlertErrorBoundaryComponent;
98+ ErrorBoundary : typeof RdAlertErrorBoundaryComponent ;
3999} ;
40100//#endregion
0 commit comments