refactor: introduce dedicated identifier types for improved clarity and type safety

This commit is contained in:
2025-11-24 23:47:36 +01:00
parent 22f0c040a2
commit 70e7bda87e
79 changed files with 1567 additions and 1572 deletions
+6 -6
View File
@@ -1,4 +1,4 @@
const ensureDate = (value: string | number | Date | null): Date | null => {
const ensureDate = (value: string | Date | null): Date | null => {
if (!value) {
return null;
}
@@ -12,7 +12,7 @@ interface FormatOptions {
options?: Intl.DateTimeFormatOptions;
}
export const formatDate = (value: string | number | Date | null, { fallback = '—', locale, options }: FormatOptions = {}): string => {
export const formatDate = (value: string | Date | null, { fallback = '—', locale, options }: FormatOptions = {}): string => {
const date = ensureDate(value);
if (!date) {
return fallback;
@@ -20,7 +20,7 @@ export const formatDate = (value: string | number | Date | null, { fallback = '
return date.toLocaleDateString(locale, options);
};
export const formatDateTime = (value: string | number | Date | null, { fallback = '—', locale, options }: FormatOptions = {}): string => {
export const formatDateTime = (value: string | Date | null, { fallback = '—', locale, options }: FormatOptions = {}): string => {
const date = ensureDate(value);
if (!date) {
return fallback;
@@ -28,7 +28,7 @@ export const formatDateTime = (value: string | number | Date | null, { fallback
return date.toLocaleString(locale, options);
};
export const toDateInputValue = (value: string | number | Date | null): string => {
export const toDateInputValue = (value: string | Date | null): string => {
const date = ensureDate(value);
if (!date) {
return '';
@@ -38,7 +38,7 @@ export const toDateInputValue = (value: string | number | Date | null): string =
return localDate.toISOString().slice(0, 10);
};
export const toIssuedTimestamp = (dateString: string | null, fallback: string | number | Date | null): string | null => {
export const toIssuedTimestamp = (dateString: string | null, fallback: string | Date | null): string | null => {
if (!dateString) {
return null;
}
@@ -52,7 +52,7 @@ export const toIssuedTimestamp = (dateString: string | null, fallback: string |
return Number.isNaN(candidate.getTime()) ? null : candidate.toISOString();
};
export const parseDateValue = (value: string | number | Date | null): Date | null => ensureDate(value);
export const parseDateValue = (value: string | Date | null): Date | null => ensureDate(value);
export default {
formatDate,
+2 -2
View File
@@ -12,9 +12,9 @@ export interface DocumentLike extends AssetManagerDocumentLike {
export type AssetLike = AssetManagerAssetLike;
export type EnsurePreviewData = (id: string | number) => Promise<DocumentLike | null>;
export type EnsurePreviewData = (id: string) => Promise<DocumentLike | null>;
export type EnsureAssetUrl = (
id: string | number,
id: string,
asset: AssetLike,
options?: { force?: boolean },
) => Promise<AssetLike | null>;