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

Update typescript #1369

Merged
merged 20 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x, 22.x]
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down
11,552 changes: 6,981 additions & 4,571 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@
"@testing-library/react": "12.1.5",
"@testing-library/user-event": "14.4.3",
"@types/jest": "26.0.20",
"eslint-config-vazco": "6.2.0",
"eslint-config-vazco": "7.4.0",
"eslint-import-resolver-alias": "1.1.2",
"eslint-import-resolver-typescript": "2.3.0",
"husky": "8.0.1",
"jest": "27.0.6",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lint-staged": "13.0.3",
"rimraf": "3.0.2",
"stylelint": "13.8.0",
"stylelint-config-prettier": "8.0.2",
"stylelint-prettier": "1.1.2",
"ts-jest": "27.0.3",
"ts-jest": "29.2.5",
"turbo": "2.1.1",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"packageManager": "[email protected]",
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/__tests__/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import userEvent, {
} from '@testing-library/user-event';
import moment from 'moment';
import React from 'react';
import { DateField } from 'uniforms-antd';
import { renderWithZod } from 'uniforms/__suites__';
import { DateField } from 'uniforms-antd';
import { z } from 'zod';

const getClosestInput = (text: string) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, screen } from '@testing-library/react';
import React from 'react';
import { SelectField } from 'uniforms-antd';
import { renderWithZod } from 'uniforms/__suites__';
import { SelectField } from 'uniforms-antd';
import { z } from 'zod';

test('<SelectField> - renders a select which correctly reacts on change (array)', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as theme from 'uniforms-antd';
import * as suites from 'uniforms/__suites__';
import * as theme from 'uniforms-antd';

it('exports everything', () => {
expect(theme).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/__tests__/wrapField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import React from 'react';
import { wrapField } from 'uniforms-antd';
import { renderWithZod } from 'uniforms/__suites__';
import { wrapField } from 'uniforms-antd';
import { z } from 'zod';

describe('wrapField tests', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/lodash": "4.17.5",
"@types/react": "17.0.39",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-antd/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function AntD(parent: any) {

return {
...props,
className: classnames('ant-form', 'ant-form-' + layout, className),
className: classnames(
'ant-form',
'ant-form-' + layout,
className as string,
),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/uniforms-antd/src/BoolField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type BoolFieldProps = FieldProps<
{
checkbox?: boolean;
checkedChildren?: ReactNode;
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
inputRef?: Ref<typeof Checkbox | typeof Switch | any>;
unCheckedChildren?: ReactNode;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/uniforms-antd/src/ListField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
Children,
cloneElement,
isValidElement,
ReactElement,
ReactNode,
} from 'react';
import { connectField, filterDOMProps, HTMLFieldProps } from 'uniforms';
Expand Down Expand Up @@ -79,7 +80,7 @@ function List({
{value?.map((item, itemIndex) =>
Children.map(children, (child, childIndex) =>
isValidElement(child)
? cloneElement(child, {
? cloneElement(child as ReactElement, {
key: `${itemIndex}-${childIndex}`,
name: child.props.name?.replace('$', '' + itemIndex),
labelCol,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-antd/src/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Radio(props: RadioFieldProps) {
name={props.name}
onChange={event => {
if (!props.readOnly) {
props.onChange(event.target.value);
props.onChange(event.target.value as string | undefined);
}
}}
value={props.value ?? ''}
Expand Down
3 changes: 2 additions & 1 deletion packages/uniforms-antd/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Select(props: SelectFieldProps) {
if (!props.readOnly) {
props.onChange(
// FIXME: Argument type depends on `props.fieldType`.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
props.fieldType === Array
? eventOrValue
: eventOrValue.target.value,
Expand All @@ -74,7 +75,7 @@ function Select(props: SelectFieldProps) {
disabled={props.disabled}
mode={props.fieldType === Array ? 'multiple' : undefined}
name={props.name}
onChange={value => {
onChange={(value: SelectFieldValue) => {
if (!props.readOnly) {
props.onChange(value);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as theme from 'uniforms-bootstrap4';
import * as suites from 'uniforms/__suites__';
import * as theme from 'uniforms-bootstrap4';

it('exports everything', () => {
expect(theme).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/__tests__/wrapField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import React from 'react';
import { wrapField } from 'uniforms-bootstrap4';
import { renderWithZod } from 'uniforms/__suites__';
import { wrapField } from 'uniforms-bootstrap4';
import { z } from 'zod';

describe('wrapField tests', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/lodash": "4.17.5",
"@types/react": "17.0.39",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Bootstrap4(parent: any) {

return {
...omit(props, ['grid']),
className: classnames('form', { error }, props.className),
className: classnames('form', { error }, props.className as string),
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/uniforms-bootstrap4/src/ListField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
Children,
cloneElement,
isValidElement,
ReactElement,
ReactNode,
} from 'react';
import { connectField, filterDOMProps, HTMLFieldProps } from 'uniforms';
Expand Down Expand Up @@ -54,7 +55,7 @@ function List({
{value?.map((item, itemIndex) =>
Children.map(children, (child, childIndex) =>
isValidElement(child)
? cloneElement(child, {
? cloneElement(child as ReactElement, {
key: `${itemIndex}-${childIndex}`,
name: child.props.name?.replace('$', '' + itemIndex),
...itemProps,
Expand Down
7 changes: 5 additions & 2 deletions packages/uniforms-bootstrap4/src/SubmitField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classnames from 'classnames';
import React, { HTMLProps, Ref } from 'react';
import { filterDOMProps, Override, useForm } from 'uniforms';

import gridClassName from './gridClassName';
import gridClassName, { GridSize } from './gridClassName';

export type SubmitFieldProps = Override<
HTMLProps<HTMLInputElement>,
Expand All @@ -24,7 +24,10 @@ function SubmitField({
...props
}: SubmitFieldProps) {
const { error, state: anyState } = useForm();
const state = anyState as unknown as { disabled: boolean; grid: any };
const state = anyState as unknown as {
disabled: boolean;
grid: number | string | Partial<Record<GridSize, number>>;
};
const hasWrap = !!(state.grid || wrapClassName);

const blockInput = (
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap4/src/gridClassName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function gridClassNamePart(
: `col-${sizeInfix}${12 - value}`;
}

type GridSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
export type GridSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
const gridOrder = { xs: 1, sm: 2, md: 3, lg: 4, xl: 5 };

function compareSizeClass(a: GridSize, b: GridSize) {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function gridClassName(
(Object.keys(grid) as GridSize[])
.sort(compareSizeClass)
// @ts-expect-error Weird type refinement problem.
.map(size => gridClassNamePart(size, grid[size], side))
.map(size => gridClassNamePart(size, grid[size] as number, side))
.join(' ')
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap5/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as theme from 'uniforms-bootstrap5';
import * as suites from 'uniforms/__suites__';
import * as theme from 'uniforms-bootstrap5';

it('exports everything', () => {
expect(theme).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap5/__tests__/wrapField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import React from 'react';
import { wrapField } from 'uniforms-bootstrap5';
import { renderWithZod } from 'uniforms/__suites__';
import { wrapField } from 'uniforms-bootstrap5';
import { z } from 'zod';

describe('wrapField tests', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/lodash": "4.17.5",
"@types/react": "17.0.39",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap5/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Bootstrap5(parent: any) {

return {
...omit(props, ['grid']),
className: classnames({ error }, props.className),
className: classnames({ error }, props.className as string),
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/uniforms-bootstrap5/src/ListField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
Children,
cloneElement,
isValidElement,
ReactElement,
ReactNode,
} from 'react';
import { connectField, filterDOMProps, HTMLFieldProps } from 'uniforms';
Expand Down Expand Up @@ -54,7 +55,7 @@ function List({
{value?.map((item, itemIndex) =>
Children.map(children, (child, childIndex) =>
isValidElement(child)
? cloneElement(child, {
? cloneElement(child as ReactElement, {
key: `${itemIndex}-${childIndex}`,
name: child.props.name?.replace('$', '' + itemIndex),
...itemProps,
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-bootstrap5/src/SubmitField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classnames from 'classnames';
import React, { HTMLProps, Ref } from 'react';
import { filterDOMProps, Override, useForm } from 'uniforms';
import { GridSize } from 'uniforms-bootstrap4/src/gridClassName';

import gridClassName from './gridClassName';

Expand All @@ -24,7 +25,10 @@ function SubmitField({
...props
}: SubmitFieldProps) {
const { error, state: anyState } = useForm();
const state = anyState as unknown as { disabled: boolean; grid: any };
const state = anyState as unknown as {
disabled: boolean;
grid: string | number | Partial<Record<GridSize, number>> | undefined;
};
const hasWrap = !!(state.grid || wrapClassName);

const blockInput = (
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap5/src/gridClassName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function gridClassName(
(Object.keys(grid) as GridSize[])
.sort(compareSizeClass)
// @ts-expect-error Weird type refinement problem.
.map(size => gridClassNamePart(size, grid[size], side))
.map(size => gridClassNamePart(size, grid[size] as number, side))
.join(' ')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,8 @@ describe('JSONSchemaBridge', () => {
});

it('works with anyOf for a non-object computed property (properties not defined)', () => {
expect(bridge.getProps('nonObjectAnyOf')).toHaveProperty(
expect(bridge.getProps('nonObjectAnyOf')).not.toHaveProperty(
'properties',
undefined,
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bridge-json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/invariant": "2.2.37",
"@types/lodash": "4.17.5",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
15 changes: 11 additions & 4 deletions packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ export default class JSONSchemaBridge extends Bridge {
partialNames.forEach(partialName => {
definition[partialName]?.forEach((partialElement: any) => {
if (!nextFound) {
partialElement = resolveRefIfNeeded(partialElement, this.schema);
partialElement = resolveRefIfNeeded(
partialElement as UnknownObject,
this.schema,
);
if (next in partialElement.properties) {
definition = partialElement.properties[next];
nextFound = true;
Expand All @@ -235,7 +238,7 @@ export default class JSONSchemaBridge extends Bridge {

partialNames.forEach(partialName => {
definition[partialName]?.forEach((partial: any) => {
partial = resolveRefIfNeeded(partial, this.schema);
partial = resolveRefIfNeeded(partial as UnknownObject, this.schema);

if (partial.required) {
required.push(...partial.required);
Expand Down Expand Up @@ -339,7 +342,9 @@ export default class JSONSchemaBridge extends Bridge {
}));
}
} else if (props.enum) {
options = Object.values(props.enum).map(value => ({ value }));
options = Object.values(props.enum as Record<string, unknown>).map(
value => ({ value }),
);
}

propsToRename.forEach(([key, newKey]) => {
Expand All @@ -364,7 +369,9 @@ export default class JSONSchemaBridge extends Bridge {
this._compiledSchema[name];

if (type === 'object' && properties) {
return Object.keys(properties).map(joinName.escape);
return Object.keys(properties as Record<string, unknown>).map(
joinName.escape,
);
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bridge-simple-schema-2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/lodash": "4.17.5",
"@types/simpl-schema": "1.12.7",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bridge-zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@types/invariant": "2.2.37",
"@types/lodash": "4.17.5",
"tslib": "2.2.0",
"typescript": "4.4.4"
"typescript": "5.5.4"
},
"scripts": {
"build:cjs": "tsc --build tsconfig.cjs.json",
Expand Down
Loading
Loading