Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Typescript to newest version #1538

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/utils/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export const useConfig = (): UseConfigFunction => {
};
};

export const withConfig = <T,>(Component: React.ComponentType<T>) => {
export const withConfig = <T extends object>(
Component: React.ComponentType<T>
) => {
return withSuffix(Component, "Config", addConfigEntries);
};

Expand Down
5 changes: 4 additions & 1 deletion src/core/utils/helpers/currency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Formats a number as a Danish Krone (DKK) currency string using the "da-DK" locale.
export function formatCurrency(number: number): string {
const options = { style: "currency", currency: "DKK" };
const options: Intl.NumberFormatOptions = {
style: "currency",
currency: "DKK"
};
return number.toLocaleString("da-DK", options);
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/utils/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export const useText = (): UseTextFunction => {
};
};

export const withText = <T,>(Component: React.ComponentType<T>) => {
export const withText = <T extends object>(
Component: React.ComponentType<T>
) => {
return withSuffix(Component, "Text", addTextEntries);
};
4 changes: 3 additions & 1 deletion src/core/utils/url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const useUrls = () => {
return urls[name];
};
};
export const withUrls = <T,>(Component: React.ComponentType<T>) => {
export const withUrls = <T extends object>(
Component: React.ComponentType<T>
) => {
return withSuffix(Component, "Url", addUrlEntries);
};

Expand Down
8 changes: 5 additions & 3 deletions src/core/utils/withSuffix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
import React from "react";
import { store } from "../store";

export default <T,>(
export default function withSuffix<T extends object>(
JacobArrow marked this conversation as resolved.
Show resolved Hide resolved
Component: React.ComponentType<T>,
suffix: string,
reduxAction: ActionCreatorWithPayload<unknown, string>
) => {
) {
return (props: T) => {
const pattern = new RegExp(`.*${suffix}$`, "g");

// Match all props that ends with suffix.
const suffixEntries = Object.fromEntries(
Object.entries(props).filter(([prop]) => {
Expand All @@ -30,10 +31,11 @@ export default <T,>(
})
);
}

// Since this is a High Order Functional Component
// we do not know what props we are dealing with.
// That is a part of the design.
// eslint-disable-next-line react/jsx-props-no-spreading
return <Component {...(nonSuffixEntries as T)} />;
};
};
}
Loading