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

Added explicit form type casting. #1003

Merged
merged 8 commits into from
Sep 13, 2021
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
18 changes: 18 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,21 @@ const ChangedForm = ({ model }) => (
</AutoForm>
);
```

### Why am I suddenly getting type errors in my form components?

After introduction of TypeScript in `uniforms@3.0.0`, in the initial versions all form components in theme packages were typed as `any`.
Natural strict typing is not possible due to TypeScript constraints. In one of the versions we have decided to change this approach and explicitly cast all of the form types.
If you experience any errors regarding form types, please [file us a bug report](https://github.com/vazco/uniforms/issues/new?assignees=&labels=&template=bug-report.md) and use one of the following workarounds for the time being in your project.

```tsx
const AnyAutoForm: any = AutoForm;
<AnyAutoForm untypedProp={1} />;

// or

const anyProps: any = {
untypedProp: 1
}
<AutoForm {...anyProps} />
```
4 changes: 2 additions & 2 deletions packages/uniforms-antd/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-antd/src/BaseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classnames from 'classnames';
import { BaseForm } from 'uniforms';

function AntD(parent: any): any {
function AntD(parent: any) {
class _ extends parent {
static AntD = AntD;

Expand All @@ -21,7 +21,7 @@ function AntD(parent: any): any {
}
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default AntD(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-antd/src/QuickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseForm from './BaseForm';
import ErrorsField from './ErrorsField';
import SubmitField from './SubmitField';

function Quick(parent: any): any {
function Quick(parent: any) {
class _ extends QuickForm.Quick(parent) {
static Quick = Quick;

Expand All @@ -22,7 +22,7 @@ function Quick(parent: any): any {
}
}

return _;
return (_ as unknown) as QuickForm;
}

export default Quick(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-antd/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ValidatedForm } from 'uniforms';

import BaseForm from './BaseForm';

function Validated(parent: any): any {
function Validated(parent: any) {
class _ extends ValidatedForm.Validated(parent) {
static Validated = Validated;
}

return _;
return (_ as unknown) as ValidatedForm;
}

export default Validated(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap3/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap3/src/BaseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classnames from 'classnames';
import { BaseForm } from 'uniforms';

function Bootstrap3(parent: any): any {
function Bootstrap3(parent: any) {
class _ extends parent {
static Bootstrap3 = Bootstrap3;

Expand Down Expand Up @@ -34,7 +34,7 @@ function Bootstrap3(parent: any): any {
}
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default Bootstrap3(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap3/src/QuickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseForm from './BaseForm';
import ErrorsField from './ErrorsField';
import SubmitField from './SubmitField';

function Quick(parent: any): any {
function Quick(parent: any) {
class _ extends QuickForm.Quick(parent) {
static Quick = Quick;

Expand All @@ -22,7 +22,7 @@ function Quick(parent: any): any {
}
}

return _;
return (_ as unknown) as QuickForm;
}

export default Quick(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap3/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ValidatedForm } from 'uniforms';

import BaseForm from './BaseForm';

function Validated(parent: any): any {
function Validated(parent: any) {
class _ extends ValidatedForm.Validated(parent) {
static Validated = Validated;
}

return _;
return (_ as unknown) as ValidatedForm;
}

export default Validated(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap4/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap4/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classnames from 'classnames';
import omit from 'lodash/omit';
import { BaseForm } from 'uniforms';

function Bootstrap4(parent: any): any {
function Bootstrap4(parent: any) {
class _ extends parent {
static Bootstrap4 = Bootstrap4;

Expand All @@ -23,7 +23,7 @@ function Bootstrap4(parent: any): any {
}
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default Bootstrap4(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap4/src/QuickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseForm from './BaseForm';
import ErrorsField from './ErrorsField';
import SubmitField from './SubmitField';

function Quick(parent: any): any {
function Quick(parent: any) {
class _ extends QuickForm.Quick(parent) {
static Quick = Quick;

Expand All @@ -22,7 +22,7 @@ function Quick(parent: any): any {
}
}

return _;
return (_ as unknown) as QuickForm;
}

export default Quick(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap4/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ValidatedForm } from 'uniforms';

import BaseForm from './BaseForm';

function Validated(parent: any): any {
function Validated(parent: any) {
class _ extends ValidatedForm.Validated(parent) {
static Validated = Validated;
}

return _;
return (_ as unknown) as ValidatedForm;
}

export default Validated(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap5/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap5/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classnames from 'classnames';
import omit from 'lodash/omit';
import { BaseForm } from 'uniforms';

function Bootstrap5(parent: any): any {
function Bootstrap5(parent: any) {
class _ extends parent {
static Bootstrap5 = Bootstrap5;

Expand All @@ -23,7 +23,7 @@ function Bootstrap5(parent: any): any {
}
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default Bootstrap5(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap5/src/QuickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseForm from './BaseForm';
import ErrorsField from './ErrorsField';
import SubmitField from './SubmitField';

function Quick(parent: any): any {
function Quick(parent: any) {
class _ extends QuickForm.Quick(parent) {
static Quick = Quick;

Expand All @@ -22,7 +22,7 @@ function Quick(parent: any): any {
}
}

return _;
return (_ as unknown) as QuickForm;
}

export default Quick(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-bootstrap5/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ValidatedForm } from 'uniforms';

import BaseForm from './BaseForm';

function Validated(parent: any): any {
function Validated(parent: any) {
class _ extends ValidatedForm.Validated(parent) {
static Validated = Validated;
}

return _;
return (_ as unknown) as ValidatedForm;
}

export default Validated(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-material/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-material/src/BaseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseForm } from 'uniforms';

function Material(parent: any): any {
function Material(parent: any) {
class _ extends parent {
static Material = Material;

static displayName = `Material${parent.displayName}`;
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default Material(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-material/src/QuickForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseForm from './BaseForm';
import ErrorsField from './ErrorsField';
import SubmitField from './SubmitField';

function Quick(parent: any): any {
function Quick(parent: any) {
class _ extends QuickForm.Quick(parent) {
static Quick = Quick;

Expand All @@ -22,7 +22,7 @@ function Quick(parent: any): any {
}
}

return _;
return (_ as unknown) as QuickForm;
}

export default Quick(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-material/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ValidatedForm } from 'uniforms';

import BaseForm from './BaseForm';

function Validated(parent: any): any {
function Validated(parent: any) {
class _ extends ValidatedForm.Validated(parent) {
static Validated = Validated;
}

return _;
return (_ as unknown) as ValidatedForm;
}

export default Validated(BaseForm);
4 changes: 2 additions & 2 deletions packages/uniforms-semantic/src/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AutoForm } from 'uniforms';

import ValidatedQuickForm from './ValidatedQuickForm';

function Auto(parent: any): any {
function Auto(parent: any) {
class _ extends AutoForm.Auto(parent) {
static Auto = Auto;
}

return _;
return (_ as unknown) as AutoForm;
}

export default Auto(ValidatedQuickForm);
4 changes: 2 additions & 2 deletions packages/uniforms-semantic/src/BaseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classnames from 'classnames';
import { BaseForm } from 'uniforms';

function Semantic(parent: any): any {
function Semantic(parent: any) {
class _ extends parent {
static Semantic = Semantic;

Expand All @@ -18,7 +18,7 @@ function Semantic(parent: any): any {
}
}

return _;
return (_ as unknown) as typeof BaseForm;
}

export default Semantic(BaseForm);
Loading