diff --git a/src/env.mjs b/src/env.ts similarity index 90% rename from src/env.mjs rename to src/env.ts index 5ef617cac..63c0d517b 100644 --- a/src/env.mjs +++ b/src/env.ts @@ -10,7 +10,7 @@ const env = import.meta.env; const envVarPrefix = 'VITE'; const DEBUG = env.MODE === 'development'; -const getEnv = name => { +const getEnv = (name: string): string | undefined => { const fullName = `${envVarPrefix}_${name}`; return env[fullName]; }; diff --git a/src/utils.js b/src/utils.ts similarity index 62% rename from src/utils.js rename to src/utils.ts index 8d70f8440..44a4fdf25 100644 --- a/src/utils.js +++ b/src/utils.ts @@ -1,4 +1,5 @@ import clsx from 'clsx'; +import type {IntlShape} from 'react-intl'; import {getEnv} from './env'; @@ -8,12 +9,12 @@ const VERSION = getEnv('VERSION'); export const PREFIX = 'openforms'; -export const getFormattedDateString = (intl, dateString) => { +export const getFormattedDateString = (intl: IntlShape, dateString: string) => { if (!dateString) return ''; return intl.formatDate(new Date(dateString)); }; -export const getFormattedTimeString = (intl, dateTimeString) => { +export const getFormattedTimeString = (intl: IntlShape, dateTimeString: string) => { if (!dateTimeString) return ''; return intl.formatTime(new Date(dateTimeString)); }; @@ -21,17 +22,17 @@ export const getFormattedTimeString = (intl, dateTimeString) => { /** * Prefix a name/string/identifier with the Open Forms specific prefix. */ -export const applyPrefix = name => { +export const applyPrefix = (name: string) => { return `${PREFIX}-${name}`; }; -export const getBEMClassName = (base, modifiers = []) => { +export const getBEMClassName = (base: string, modifiers: string[] = []) => { const prefixedBase = applyPrefix(base); const prefixedModifiers = modifiers.map(mod => applyPrefix(`${base}--${mod}`)); return clsx(prefixedBase, ...prefixedModifiers); }; // usage: await sleep(3000); -export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); +export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); export const getVersion = () => VERSION || 'unknown'; diff --git a/tsconfig.json b/tsconfig.json index 3464dd4ea..485d53111 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "@/sb-decorators": ["../.storybook/decorators.tsx"] }, "types": [ + "vite/client", "vitest/globals" ] },