Skip to content

Commit

Permalink
chore: migrate FormattedNumber component from jsx to tsx (#17361)
Browse files Browse the repository at this point in the history
* migrate FormattedNumber component from jsx to tsx

* Unset default prop on format

* undo asserting and overriding the type for num

* Add a ts comment to ignore error
  • Loading branch information
Damans227 committed Nov 22, 2021
1 parent 16e012f commit daff9b4
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,19 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { formatNumber } from '@superset-ui/core';

const propTypes = {
num: PropTypes.number,
format: PropTypes.string,
};

const defaultProps = {
num: 0,
format: undefined,
};
interface FormattedNumberProps {
num?: string | number;
format?: string;
}

function FormattedNumber({ num, format }) {
function FormattedNumber({ num = 0, format }: FormattedNumberProps) {
if (format) {
return <span title={num}>{formatNumber(format, num)}</span>;
// @ts-expect-error formatNumber can actually accept strings, even though it's not typed as such
return <span title={`${num}`}>{formatNumber(format, num)}</span>;
}
return <span>{num}</span>;
}

FormattedNumber.propTypes = propTypes;
FormattedNumber.defaultProps = defaultProps;

export default FormattedNumber;

0 comments on commit daff9b4

Please sign in to comment.