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 all commits
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
42 changes: 10 additions & 32 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ Cypress.Commands.add("createFakeAuthenticatedSession", () => {
window.sessionStorage.setItem(TOKEN_USER_KEY, "999");
});

Cypress.Commands.add("createFakeLibrarySession", () => {
// Since the user token is shared in storybook by setting it in sessionStorage
// we can use that and fake that we have a inlogged user session
// by using the same principle.
// See userToken handling in .storybbok/preview.js.
window.sessionStorage.setItem(TOKEN_LIBRARY_KEY, "random-token");
});

/**
* interceptGraphql is used to make a graphQLrequest that returns fixture data
*
Expand Down Expand Up @@ -94,22 +86,18 @@ Cypress.Commands.add(

// Data cy attribute selector helpers.
const visible = (checkVisible: boolean) => (checkVisible ? ":visible" : "");
Cypress.Commands.add("getBySel", (selector, checkVisible = false, ...args) => {
return cy.get(`[data-cy="${selector}"]${visible(checkVisible)}`, ...args);
Cypress.Commands.add("getBySel", (selector, checkVisible = false) => {
return cy.get(`[data-cy="${selector}"]${visible(checkVisible)}`);
});
Cypress.Commands.add("getBySelLike", (selector, checkVisible = false) => {
return cy.get(`[data-cy*="${selector}"]${visible(checkVisible)}`);
});
Cypress.Commands.add(
"getBySelLike",
(selector, checkVisible = false, ...args) => {
return cy.get(`[data-cy*="${selector}"]${visible(checkVisible)}`, ...args);
}
);
Cypress.Commands.add(
"getBySelStartEnd",
(startSelector, endSelector, checkVisible = false, ...args) => {
(startSelector, endSelector, checkVisible = false) => {
const v = visible(checkVisible);
return cy.get(
`[data-cy^="${startSelector}"]${v}[data-cy$="${endSelector}"]${v}`,
...args
`[data-cy^="${startSelector}"]${v}[data-cy$="${endSelector}"]${v}`
);
}
);
Expand All @@ -123,24 +111,14 @@ declare global {
*/
createFakeLibrarySession(): void;
createFakeAuthenticatedSession(): void;
createFakeLibrarySession(): void;
interceptGraphql(prams: InterceptGraphqlParams): void;
interceptRest(params: InterceptRestParams): void;
getBySel(
selector: string,
checkVisible?: boolean,
...args: unknown[]
): Chainable;
getBySelLike(
selector: string,
checkVisible?: boolean,
...args: unknown[]
): Chainable;
getBySel(selector: string, checkVisible?: boolean): Chainable;
getBySelLike(selector: string, checkVisible?: boolean): Chainable;
getBySelStartEnd(
startSelector: string,
endSelector: string,
checkVisible?: boolean,
...args: unknown[]
checkVisible?: boolean
): Chainable;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"stylelint-webpack-plugin": "^5.0.1",
"svg-url-loader": "^8.0.0",
"ts-node": "^10.9.2",
"typescript": "^4.6.4",
"typescript": "^5.6.0",
"vitest": "^0.28.5",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/apps/advanced-search/AdvancedSearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const AdvancedSearchHeader: React.FC<AdvancedSearchHeaderProps> = ({
type="button"
className="link-tag advanced-search__back-button cursor-pointer"
onClick={() => setIsFormMode(true)}
onKeyUp={(e) => e.key === "Enter" ?? setIsFormMode(!true)}
onKeyUp={(e) => e.key === "Enter" && setIsFormMode(!true)}
>
{t("toAdvancedSearchButtonText")}
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/apps/advanced-search/PreviewSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const PreviewSection: React.FC<PreviewSectionProps> = ({
type="button"
className="link-tag link-tag cursor-pointer capitalize-first"
onClick={() => setIsFormMode(false)}
onKeyUp={(e) => e.key === "Enter" ?? setIsFormMode(false)}
onKeyUp={(e) => e.key === "Enter" && setIsFormMode(false)}
data-cy="advanced-search-edit-cql"
>
{t("advancedSearchEditCqlText")}
Expand Down
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)} />;
};
};
}
39 changes: 7 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12682,7 +12682,7 @@ [email protected], string-env-interpolation@^1.0.1:
resolved "https://registry.npmjs.org/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz"
integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg==

"string-width-cjs@npm:string-width@^4.2.0":
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -12717,15 +12717,6 @@ string-width@^3.0.0, string-width@^3.1.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -12820,7 +12811,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -12848,13 +12839,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1, strip-ansi@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -13596,10 +13580,10 @@ typedarray@^0.0.6:
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^4.6.4:
version "4.6.4"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
typescript@^5.6.0:
version "5.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b"
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==

ua-parser-js@^0.7.30:
version "0.7.36"
Expand Down Expand Up @@ -14281,7 +14265,7 @@ wildcard@^2.0.0:
resolved "https://registry.npmjs.org/wildcard/-/wildcard-2.0.0.tgz"
integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down Expand Up @@ -14316,15 +14300,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
Loading