diff --git a/docs/faq.md b/docs/faq.md index 9a9f71e62..688540f43 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -245,3 +245,21 @@ const ChangedForm = ({ model }) => ( ); ``` + +### 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; +; + +// or + +const anyProps: any = { + untypedProp: 1 +} + +``` diff --git a/packages/uniforms-antd/src/AutoForm.tsx b/packages/uniforms-antd/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-antd/src/AutoForm.tsx +++ b/packages/uniforms-antd/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-antd/src/BaseForm.tsx b/packages/uniforms-antd/src/BaseForm.tsx index 798ed59a7..6ba42984b 100644 --- a/packages/uniforms-antd/src/BaseForm.tsx +++ b/packages/uniforms-antd/src/BaseForm.tsx @@ -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; @@ -21,7 +21,7 @@ function AntD(parent: any): any { } } - return _; + return (_ as unknown) as typeof BaseForm; } export default AntD(BaseForm); diff --git a/packages/uniforms-antd/src/QuickForm.tsx b/packages/uniforms-antd/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-antd/src/QuickForm.tsx +++ b/packages/uniforms-antd/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-antd/src/ValidatedForm.tsx b/packages/uniforms-antd/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-antd/src/ValidatedForm.tsx +++ b/packages/uniforms-antd/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap3/src/AutoForm.tsx b/packages/uniforms-bootstrap3/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-bootstrap3/src/AutoForm.tsx +++ b/packages/uniforms-bootstrap3/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap3/src/BaseForm.tsx b/packages/uniforms-bootstrap3/src/BaseForm.tsx index 18fb80283..626849a46 100644 --- a/packages/uniforms-bootstrap3/src/BaseForm.tsx +++ b/packages/uniforms-bootstrap3/src/BaseForm.tsx @@ -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; @@ -34,7 +34,7 @@ function Bootstrap3(parent: any): any { } } - return _; + return (_ as unknown) as typeof BaseForm; } export default Bootstrap3(BaseForm); diff --git a/packages/uniforms-bootstrap3/src/QuickForm.tsx b/packages/uniforms-bootstrap3/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-bootstrap3/src/QuickForm.tsx +++ b/packages/uniforms-bootstrap3/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-bootstrap3/src/ValidatedForm.tsx b/packages/uniforms-bootstrap3/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-bootstrap3/src/ValidatedForm.tsx +++ b/packages/uniforms-bootstrap3/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap4/src/AutoForm.tsx b/packages/uniforms-bootstrap4/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-bootstrap4/src/AutoForm.tsx +++ b/packages/uniforms-bootstrap4/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap4/src/BaseForm.tsx b/packages/uniforms-bootstrap4/src/BaseForm.tsx index 711059c0d..372bf8b28 100644 --- a/packages/uniforms-bootstrap4/src/BaseForm.tsx +++ b/packages/uniforms-bootstrap4/src/BaseForm.tsx @@ -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; @@ -23,7 +23,7 @@ function Bootstrap4(parent: any): any { } } - return _; + return (_ as unknown) as typeof BaseForm; } export default Bootstrap4(BaseForm); diff --git a/packages/uniforms-bootstrap4/src/QuickForm.tsx b/packages/uniforms-bootstrap4/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-bootstrap4/src/QuickForm.tsx +++ b/packages/uniforms-bootstrap4/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-bootstrap4/src/ValidatedForm.tsx b/packages/uniforms-bootstrap4/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-bootstrap4/src/ValidatedForm.tsx +++ b/packages/uniforms-bootstrap4/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap5/src/AutoForm.tsx b/packages/uniforms-bootstrap5/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-bootstrap5/src/AutoForm.tsx +++ b/packages/uniforms-bootstrap5/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-bootstrap5/src/BaseForm.tsx b/packages/uniforms-bootstrap5/src/BaseForm.tsx index 2b99b731a..7a93c475a 100644 --- a/packages/uniforms-bootstrap5/src/BaseForm.tsx +++ b/packages/uniforms-bootstrap5/src/BaseForm.tsx @@ -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; @@ -23,7 +23,7 @@ function Bootstrap5(parent: any): any { } } - return _; + return (_ as unknown) as typeof BaseForm; } export default Bootstrap5(BaseForm); diff --git a/packages/uniforms-bootstrap5/src/QuickForm.tsx b/packages/uniforms-bootstrap5/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-bootstrap5/src/QuickForm.tsx +++ b/packages/uniforms-bootstrap5/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-bootstrap5/src/ValidatedForm.tsx b/packages/uniforms-bootstrap5/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-bootstrap5/src/ValidatedForm.tsx +++ b/packages/uniforms-bootstrap5/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-material/src/AutoForm.tsx b/packages/uniforms-material/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-material/src/AutoForm.tsx +++ b/packages/uniforms-material/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-material/src/BaseForm.tsx b/packages/uniforms-material/src/BaseForm.tsx index 8ee86a432..18901966f 100644 --- a/packages/uniforms-material/src/BaseForm.tsx +++ b/packages/uniforms-material/src/BaseForm.tsx @@ -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); diff --git a/packages/uniforms-material/src/QuickForm.tsx b/packages/uniforms-material/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-material/src/QuickForm.tsx +++ b/packages/uniforms-material/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-material/src/ValidatedForm.tsx b/packages/uniforms-material/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-material/src/ValidatedForm.tsx +++ b/packages/uniforms-material/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-semantic/src/AutoForm.tsx b/packages/uniforms-semantic/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-semantic/src/AutoForm.tsx +++ b/packages/uniforms-semantic/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-semantic/src/BaseForm.tsx b/packages/uniforms-semantic/src/BaseForm.tsx index c850a34aa..d6a1ad99a 100644 --- a/packages/uniforms-semantic/src/BaseForm.tsx +++ b/packages/uniforms-semantic/src/BaseForm.tsx @@ -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; @@ -18,7 +18,7 @@ function Semantic(parent: any): any { } } - return _; + return (_ as unknown) as typeof BaseForm; } export default Semantic(BaseForm); diff --git a/packages/uniforms-semantic/src/QuickForm.tsx b/packages/uniforms-semantic/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-semantic/src/QuickForm.tsx +++ b/packages/uniforms-semantic/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-semantic/src/ValidatedForm.tsx b/packages/uniforms-semantic/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-semantic/src/ValidatedForm.tsx +++ b/packages/uniforms-semantic/src/ValidatedForm.tsx @@ -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); diff --git a/packages/uniforms-unstyled/src/AutoForm.tsx b/packages/uniforms-unstyled/src/AutoForm.tsx index a8f25da9c..dd83b25bb 100644 --- a/packages/uniforms-unstyled/src/AutoForm.tsx +++ b/packages/uniforms-unstyled/src/AutoForm.tsx @@ -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); diff --git a/packages/uniforms-unstyled/src/BaseForm.tsx b/packages/uniforms-unstyled/src/BaseForm.tsx index b1a6bb8af..2dd419472 100644 --- a/packages/uniforms-unstyled/src/BaseForm.tsx +++ b/packages/uniforms-unstyled/src/BaseForm.tsx @@ -1,13 +1,13 @@ import { BaseForm } from 'uniforms'; -function Unstyled(parent: any): any { +function Unstyled(parent: any) { class _ extends parent { static Unstyled = Unstyled; static displayName = `Unstyled${parent.displayName}`; } - return _; + return (_ as unknown) as typeof BaseForm; } export default Unstyled(BaseForm); diff --git a/packages/uniforms-unstyled/src/QuickForm.tsx b/packages/uniforms-unstyled/src/QuickForm.tsx index c12584608..99930e213 100644 --- a/packages/uniforms-unstyled/src/QuickForm.tsx +++ b/packages/uniforms-unstyled/src/QuickForm.tsx @@ -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; @@ -22,7 +22,7 @@ function Quick(parent: any): any { } } - return _; + return (_ as unknown) as QuickForm; } export default Quick(BaseForm); diff --git a/packages/uniforms-unstyled/src/ValidatedForm.tsx b/packages/uniforms-unstyled/src/ValidatedForm.tsx index 15aa5dbb1..fa18a2d26 100644 --- a/packages/uniforms-unstyled/src/ValidatedForm.tsx +++ b/packages/uniforms-unstyled/src/ValidatedForm.tsx @@ -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); diff --git a/website/lib/universal.tsx b/website/lib/universal.tsx index e91509d35..edda486a2 100644 --- a/website/lib/universal.tsx +++ b/website/lib/universal.tsx @@ -44,9 +44,10 @@ export const themes = { export const themeContext = createContext('unstyled'); function _createThemedComponent(component: keyof typeof unstyled) { - return function ThemedComponent(props: Record) { + return function ThemedComponent(props: Record) { const theme = useContext(themeContext); - const Component = themes[theme][component]; + // FIXME: Form prop errors due to `props` having no strict type here. + const Component: any = themes[theme][component]; return ; }; }