Browse Source

🔷 Fix Result status type to string & number (#21691)

close #21592
pull/21887/head
偏右 5 years ago
committed by afc163
parent
commit
a473770836
  1. 23
      components/result/__tests__/type.test.tsx
  2. 4
      components/result/index.tsx

23
components/result/__tests__/type.test.tsx

@ -0,0 +1,23 @@
import * as React from 'react';
import Result from '..';
describe('Result.typescript', () => {
it('status', () => {
const result = (
<>
<Result
status="404"
title="404"
subTitle="Sorry, the page you visited does not exist."
/>
<Result
status={404}
title="404"
subTitle="Sorry, the page you visited does not exist."
/>
</>
);
expect(result).toBeTruthy();
});
});

4
components/result/index.tsx

@ -19,7 +19,7 @@ export const ExceptionMap = {
'403': unauthorized,
};
export type ExceptionStatusType = keyof typeof ExceptionMap;
export type ExceptionStatusType = 403 | 404 | 500 | '403' | '404' | '500';
export type ResultStatusType = ExceptionStatusType | keyof typeof IconMap;
export interface ResultProps {
@ -46,7 +46,7 @@ const ExceptionStatus = Object.keys(ExceptionMap);
const renderIcon = (prefixCls: string, { status, icon }: ResultProps) => {
const className = classnames(`${prefixCls}-icon`);
if (ExceptionStatus.includes(status as ResultStatusType)) {
if (ExceptionStatus.includes(`${status}`)) {
const SVGComponent = ExceptionMap[status as ExceptionStatusType];
return (
<div className={`${className} ${prefixCls}-image`}>

Loading…
Cancel
Save