From fddd7ab5bf62d145a0d0f6afc08cad74413edc73 Mon Sep 17 00:00:00 2001 From: Alexander Wood Date: Thu, 14 Aug 2025 20:59:44 +0100 Subject: [PATCH 1/4] improve typing of text-format --- src/formatter/text-format.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/formatter/text-format.tsx b/src/formatter/text-format.tsx index 10cab16..c1a687f 100644 --- a/src/formatter/text-format.tsx +++ b/src/formatter/text-format.tsx @@ -18,24 +18,32 @@ */ import React from 'react'; import numeral from 'numeral'; -import dayjs from 'dayjs'; +import dayjs, { Dayjs } from 'dayjs'; import TranslatorContext from '../language/translator-context'; import 'numeral/locales'; -export type ITextFormatTypes = 'date' | 'number'; - -export interface ITextFormatProps { - value: string | number | Date; - type: ITextFormatTypes; +interface CommonTextFormatProps { format?: string; blankOnInvalid?: boolean; locale?: string; } +interface ITextFormatDateProps extends CommonTextFormatProps { + value: Date | Dayjs; + type: 'date'; +} + +interface ITextFormatNumberProps extends CommonTextFormatProps { + value: number | string; + type: 'number'; +} + +export type ITextFormatProps = ITextFormatDateProps | ITextFormatNumberProps; + /** * Formats the given value to specified type like date or number. * @param value value to be formatted - * @param type type of formatting to use ${ITextFormatTypes} + * @param type type of formatting to use (`date` or `number`) * @param format optional format to use. * For date type dayjs(https://day.js.org/docs/en/display/format) format is used * For number type NumeralJS (http://numeraljs.com/#format) format is used From 29fdfe417bc40b97a71613319157c18fc9f6cd96 Mon Sep 17 00:00:00 2001 From: Alexander Wood Date: Thu, 14 Aug 2025 20:59:48 +0100 Subject: [PATCH 2/4] fix dependency issue --- package-lock.json | 8 ++++++++ package.json | 1 + 2 files changed, 9 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9e8dbb3..2ad757f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ }, "devDependencies": { "@testing-library/react": "^16.1.0", + "@types/numeral": "^2.0.5", "@types/react": "^18.3.14", "@types/react-dom": "^18.3.2", "@types/sanitize-html": "^2.13.0", @@ -1568,6 +1569,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/numeral": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/numeral/-/numeral-2.0.5.tgz", + "integrity": "sha512-kH8I7OSSwQu9DS9JYdFWbuvhVzvFRoCPCkGxNwoGgaPeDfEPJlcxNvEOypZhQ3XXHsGbfIuYcxcJxKUfJHnRfw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/parse-json": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz", diff --git a/package.json b/package.json index 702120c..fc42ff4 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ }, "devDependencies": { "@testing-library/react": "^16.1.0", + "@types/numeral": "^2.0.5", "@types/react": "^18.3.14", "@types/react-dom": "^18.3.2", "@types/sanitize-html": "^2.13.0", From d572e9a40ba7b44ada5eb7a6c894dbac564c548c Mon Sep 17 00:00:00 2001 From: Alexander Wood Date: Thu, 14 Aug 2025 21:04:01 +0100 Subject: [PATCH 3/4] use dayjs.ConfigType --- src/formatter/text-format.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter/text-format.tsx b/src/formatter/text-format.tsx index c1a687f..7216b4d 100644 --- a/src/formatter/text-format.tsx +++ b/src/formatter/text-format.tsx @@ -29,7 +29,7 @@ interface CommonTextFormatProps { } interface ITextFormatDateProps extends CommonTextFormatProps { - value: Date | Dayjs; + value: dayjs.ConfigType; type: 'date'; } From d30af790b3d7856da8a485354c3ccf23ff30b928 Mon Sep 17 00:00:00 2001 From: Alexander Wood Date: Thu, 14 Aug 2025 21:07:40 +0100 Subject: [PATCH 4/4] fix eslint error --- src/formatter/text-format.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter/text-format.tsx b/src/formatter/text-format.tsx index 7216b4d..c47abe3 100644 --- a/src/formatter/text-format.tsx +++ b/src/formatter/text-format.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import numeral from 'numeral'; -import dayjs, { Dayjs } from 'dayjs'; +import dayjs from 'dayjs'; import TranslatorContext from '../language/translator-context'; import 'numeral/locales';