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

Chore/deps migrate typescript v5 #1900

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion configs/typescript-config-spirit/dom.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

// If types is specified, only packages listed will be included in the global scope.
// @see: https://www.typescriptlang.org/tsconfig/#types
"types": ["node", "jest", "@testing-library/jest-dom"]
"types": ["node", "jest", "@testing-library/jest-dom"],

// Specify multiple folders that act like './node_modules/@types'.
// @see: https://www.typescriptlang.org/tsconfig/#typeRoots
"typeRoots": ["../../node_modules/@types", "../../node_modules"]
}
}
2 changes: 1 addition & 1 deletion exporters/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../configs/typescript-config-spirit/dom",
"extends": "../../configs/typescript-config-spirit/base",
"include": ["./src/**/*"],
"exclude": ["./node_modules", "./dist/**/*"]
}
2 changes: 1 addition & 1 deletion exporters/scss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../configs/typescript-config-spirit/dom",
"extends": "../../configs/typescript-config-spirit/base",
"include": ["./src/**/*"],
"exclude": ["./node_modules", "./dist/**/*"]
}
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@
"remark-lint-heading-capitalization": "1.3.0",
"sass-loader": "14.2.1",
"style-loader": "4.0.0",
"typescript": "4.7.4",
"typescript": "5.6.3",
"vite-raw-plugin": "1.0.2",
"webpack": "5.96.1",
"webpack-cli": "5.1.4"
},
"resolutions": {
"typescript": "4.7.4"
},
"packageManager": "yarn@4.6.0"
}
2 changes: 1 addition & 1 deletion packages/form-validations/src/FormValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class FormValidations {

if (typeof input !== 'boolean') {
if (input instanceof HTMLElement) {
fields = [input.formValidations];
fields = [(input as FormValidationsElement).formValidations];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
} else if (input instanceof NodeList || input instanceof Array) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-react/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaultProps: Partial<SpiritAlertProps> = {
elementType: 'div',
};

export const Alert = <T extends ElementType = 'div', E = void>(props: SpiritAlertProps<T, E>): JSX.Element => {
export const Alert = <T extends ElementType = 'div', E = void>(props: SpiritAlertProps<T, E>) => {
const propsWithDefaults = { ...defaultProps, ...props };
const {
elementType: ElementTag = defaultProps.elementType as ElementType,
Expand Down
10 changes: 5 additions & 5 deletions packages/web-react/src/components/Flex/useFlexStyleProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useSpacingStyle,
useWrapClass,
} from '../../hooks';
import { FlexAlignmentXType, FlexAlignmentYType, SpacingProp, SpiritFlexProps } from '../../types';
import { FlexAlignmentXType, FlexAlignmentYType, SpacingType, SpiritFlexProps } from '../../types';
import { generateStylePropsClassNames, stringOrObjectKebabCaseToCamelCase } from '../../utils';

interface FlexCSSProperties extends CSSProperties {
Expand Down Expand Up @@ -39,10 +39,10 @@ export function useFlexStyleProps(props: SpiritFlexProps<ElementType>): FlexStyl
const flexClass = useClassNamePrefix('Flex');

const flexStyle: FlexCSSProperties = {
...useSpacingStyle(spacing as SpacingProp, 'flex', DirectionAxis.X),
...useSpacingStyle(spacing as SpacingProp, 'flex', DirectionAxis.Y),
...useSpacingStyle(spacingX as SpacingProp, 'flex', DirectionAxis.X),
...useSpacingStyle(spacingY as SpacingProp, 'flex', DirectionAxis.Y),
...useSpacingStyle(spacing as SpacingType, 'flex', DirectionAxis.X),
...useSpacingStyle(spacing as SpacingType, 'flex', DirectionAxis.Y),
...useSpacingStyle(spacingX as SpacingType, 'flex', DirectionAxis.X),
...useSpacingStyle(spacingY as SpacingType, 'flex', DirectionAxis.Y),
};

const directionClass = generateStylePropsClassNames(flexClass, stringOrObjectKebabCaseToCamelCase(direction!));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from '@testing-library/react';
import { DirectionAxis } from '../../constants';
import { SpacingProp } from '../../types';
import { SpacingType } from '../../types';
import { useSpacingStyle } from '../useSpacingStyle';

describe('useSpacingStyles', () => {
Expand All @@ -11,7 +11,7 @@ describe('useSpacingStyles', () => {
desktop: 'space-300',
};

const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingProp, 'test-prefix'));
const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingType, 'test-prefix'));

expect(result.current).toEqual({
'--test-prefix-spacing': 'var(--spirit-space-100)',
Expand All @@ -23,7 +23,7 @@ describe('useSpacingStyles', () => {
it('should process if spacing is a string', () => {
const mockProps = 'space-100';

const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingProp, 'test-prefix'));
const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingType, 'test-prefix'));

expect(result.current).toEqual({
'--test-prefix-spacing': 'var(--spirit-space-100)',
Expand All @@ -37,7 +37,7 @@ describe('useSpacingStyles', () => {
desktop: 'space-300',
};

const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingProp, 'test-prefix', DirectionAxis.X));
const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingType, 'test-prefix', DirectionAxis.X));

expect(result.current).toEqual({
'--test-prefix-spacing-x': 'var(--spirit-space-100)',
Expand All @@ -49,7 +49,7 @@ describe('useSpacingStyles', () => {
it('should process vertical direction with spacing if property spacing is a string', () => {
const mockProps = 'space-100';

const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingProp, 'test-prefix', DirectionAxis.Y));
const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingType, 'test-prefix', DirectionAxis.Y));

expect(result.current).toEqual({
'--test-prefix-spacing-y': 'var(--spirit-space-100)',
Expand All @@ -59,7 +59,7 @@ describe('useSpacingStyles', () => {
it('should process if spacing is undefined', () => {
const mockProps = undefined;

const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingProp | undefined, 'test-prefix'));
const { result } = renderHook(() => useSpacingStyle(mockProps as SpacingType | undefined, 'test-prefix'));

expect(result.current).toEqual({});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/hooks/useSpacingStyle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DirectionAxis } from '../constants';
import { SpacingProp, SpacingCSSProperties } from '../types';
import { SpacingCSSProperties, SpacingType } from '../types';

export function useSpacingStyle(
spacing: SpacingProp | undefined,
spacing: SpacingType | undefined,
prefix: string,
direction: undefined | (typeof DirectionAxis)[keyof typeof DirectionAxis] = undefined,
): SpacingCSSProperties {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/types/alert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, JSXElementConstructor } from 'react';
import { ElementType } from 'react';
import { ChildrenProps, EmotionColorsDictionaryType, StyleProps, TransferProps } from './shared';

export interface AriaAlertElementTypeProps<T extends ElementType = 'div'> {
Expand All @@ -7,7 +7,7 @@ export interface AriaAlertElementTypeProps<T extends ElementType = 'div'> {
*
* @default 'div'
*/
elementType?: T | JSXElementConstructor<unknown>;
elementType?: T;
}

export interface AlertProps extends ChildrenProps, StyleProps, TransferProps {}
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/types/avatar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, JSXElementConstructor } from 'react';
import { ElementType } from 'react';
import { ChildrenProps, SizeExtendedDictionaryType, StyleProps, TransferProps } from './shared';

export type AvatarSize<S> = SizeExtendedDictionaryType<S> | S;
Expand All @@ -9,7 +9,7 @@ export interface AriaAvatarElementTypeProps<E extends ElementType = 'div'> {
*
* @default 'div'
*/
elementType?: E | JSXElementConstructor<unknown>;
elementType?: E;
}

export interface AvatarProps extends ChildrenProps, StyleProps, TransferProps {}
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/types/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, JSXElementConstructor } from 'react';
import { ElementType } from 'react';
import { ChildrenProps, StyleProps, TransferProps } from './shared';

type BreadcrumbsItem = {
Expand All @@ -22,7 +22,7 @@ export interface AriaBreadcrumbsElementTypeProps<T extends ElementType = 'nav'>
*
* @default 'nav'
*/
elementType?: T | JSXElementConstructor<unknown>;
elementType?: T;
}

export interface BreadcrumbsStyleProps extends StyleProps, TransferProps {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/types/pill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, JSXElementConstructor } from 'react';
import { ElementType } from 'react';
import { ChildrenProps, EmotionColorsDictionaryType, TransferProps } from './shared';

export type PillColor<C> = EmotionColorsDictionaryType | 'selected' | 'neutral' | C;
Expand All @@ -9,7 +9,7 @@ export interface AriaPillElementTypeProps<T extends ElementType = 'span'> {
*
* @default 'span'
*/
elementType?: T | JSXElementConstructor<unknown>;
elementType?: T;
}

export interface SpiritPillProps<T extends ElementType = 'span', C = void>
Expand Down
4 changes: 3 additions & 1 deletion packages/web-react/src/types/shared/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export type SpacingProps = {
| Partial<Record<BreakpointToken, SpaceToken | StyleSpacingAuto>>;
};

export type SpacingType = SpaceToken | Partial<Record<BreakpointToken, SpaceToken>>;

export interface SpacingProp {
spacing?: SpaceToken | Partial<Record<BreakpointToken, SpaceToken>>;
spacing?: SpacingType;
}

export interface SpacingCSSProperties extends CSSProperties {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/types/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, JSXElementConstructor } from 'react';
import { ElementType } from 'react';
import {
ChildrenProps,
EmphasisDictionaryType,
Expand All @@ -15,7 +15,7 @@ export interface TextElementTypeProps<T extends ElementType = 'p'> {
*
* @default 'p'
*/
elementType?: T | JSXElementConstructor<unknown>;
elementType?: T;
}

export interface TextProps<T extends ElementType = 'p'>
Expand Down
1 change: 1 addition & 0 deletions packages/web/config/jest/setupTestingLibrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
9 changes: 9 additions & 0 deletions packages/web/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const config = {
preset: 'jest-config-spirit/jsdom',

/**
* @todo Move this configuration to the `jest-config-spirit` preset
*
* @see { @link https://github.com/lmc-eu/spirit-design-system/issues/1413 }
*/
// A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed.
// https://jestjs.io/docs/configuration#setupfilesafterenv-array
setupFilesAfterEnv: ['<rootDir>/config/jest/setupTestingLibrary.ts'],
};

export default config;
2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@rollup/plugin-replace": "6.0.2",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "12.1.2",
"@testing-library/jest-dom": "^6.6.3",
"@types/eslint": "9.6.1",
"@types/jest": "29.5.14",
"autoprefixer": "10.4.20",
Expand All @@ -80,6 +81,7 @@
"shx": "0.3.4",
"stylelint": "16.14.1",
"stylelint-config-spirit": "workspace:^",
"ts-node": "^10.9.2",
"tslib": "2.8.1",
"typescript": "5.6.3"
},
Expand Down
Loading
Loading