From 67bbb2d33348d5077d0e28a0d42df5e4db75eb5b Mon Sep 17 00:00:00 2001 From: VaiTon Date: Mon, 24 Jul 2023 19:01:58 +0200 Subject: [PATCH] chore: converted const.js and reportWebVitals.js to TS --- package.json | 1 + src/{const.js => const.ts} | 0 src/reportWebVitals.js | 13 ------------- src/reportWebVitals.ts | 15 +++++++++++++++ yarn.lock | 8 ++++++++ 5 files changed, 24 insertions(+), 13 deletions(-) rename src/{const.js => const.ts} (100%) delete mode 100644 src/reportWebVitals.js create mode 100644 src/reportWebVitals.ts diff --git a/package.json b/package.json index 6aedb41a3..4248cc31c 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "web-vitals": "^3.0.4" }, "devDependencies": { + "@types/node": "^20.4.4", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.6", "@vitejs/plugin-react": "^4.0.2", diff --git a/src/const.js b/src/const.ts similarity index 100% rename from src/const.js rename to src/const.ts diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js deleted file mode 100644 index 9ecd33f9c..000000000 --- a/src/reportWebVitals.js +++ /dev/null @@ -1,13 +0,0 @@ -const reportWebVitals = (onPerfEntry) => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/src/reportWebVitals.ts b/src/reportWebVitals.ts new file mode 100644 index 000000000..360ea59e0 --- /dev/null +++ b/src/reportWebVitals.ts @@ -0,0 +1,15 @@ +const reportWebVitals = async ( + onPerfEntry: undefined | ((value: any) => void) = undefined +) => { + if (onPerfEntry && onPerfEntry instanceof Function) { + const { onCLS, onFID, onFCP, onLCP, onTTFB } = await import("web-vitals"); + + onCLS(onPerfEntry); + onFID(onPerfEntry); + onFCP(onPerfEntry); + onLCP(onPerfEntry); + onTTFB(onPerfEntry); + } +}; + +export default reportWebVitals; diff --git a/yarn.lock b/yarn.lock index 28dfa9be8..e4d662281 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1007,6 +1007,13 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^20.4.4": + version: 20.4.4 + resolution: "@types/node@npm:20.4.4" + checksum: 43f3c4a8acc38ae753e15a0e79bae0447d255b3742fa87f8e065d7b9d20ecb0e03d6c5b46c00d5d26f4552160381a00255f49205595a8ee48c2423e00263c930 + languageName: node + linkType: hard + "@types/parse-json@npm:^4.0.0": version: 4.0.0 resolution: "@types/parse-json@npm:4.0.0" @@ -2029,6 +2036,7 @@ __metadata: "@mui/material": ^5.11.7 "@mui/x-data-grid": ^5.17.22 "@reduxjs/toolkit": ^1.9.1 + "@types/node": ^20.4.4 "@types/react": ^18.0.27 "@types/react-dom": ^18.0.6 "@vitejs/plugin-react": ^4.0.2