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

Improved typings. #949

Merged
merged 2 commits into from
May 7, 2021
Merged

Improved typings. #949

merged 2 commits into from
May 7, 2021

Conversation

radekmie
Copy link
Contributor

@radekmie radekmie commented May 6, 2021

This PR improves typings in a few ways:

  • Update to TypeScript 4.2.4 makes some of the generated .d.ts files much shorter.
  • Overhaul of the typings in createAutoField and connectField.
    • The former is trivial: extracting "temporary" types into named and exported ones makes them usable in the .d.ts files.
    • The latter was similar, however, these types were more complex. As a result, there are three new types: ConnectFieldOptions, ConnectedFieldProps<Props, Value>, and ConnectedField<Props, Value.
      • All three got marked as @internal and I think that's the way to go - let's mark "actually internal" types with this JSDoc.

As a result, multiple .d.ts files are much smaller now.

uniforms-antd/es5/AutoField.d.ts before - 2831B
/// <reference types="react" />
export declare type AutoFieldProps = Parameters<typeof AutoField>[0];
declare const AutoField: {
    (rawProps: import("uniforms").Override<Record<string, unknown>, {
        component?: import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | (import("react").FunctionComponent<import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<any>>, import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<unknown>>, {
            label?: import("react").ReactNode;
            name: string;
            placeholder?: string | boolean | null | undefined;
        }>>> & {
            Component: import("react").ComponentType<Partial<import("uniforms").GuaranteedProps<any>>>;
            options: {
                initialValue?: boolean | undefined;
                kind?: "leaf" | "node" | undefined;
            } | undefined;
        }) | undefined;
        name: string;
    }>): import("react").ReactElement<any, string | ((props: any) => import("react").ReactElement<any, any> | null) | (new (props: any) => import("react").Component<any, any, any>)>;
    componentDetectorContext: import("react").Context<(props: import("uniforms").GuaranteedProps<unknown> & Record<string, any>, uniforms: import("uniforms").Context<unknown>) => import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | (import("react").FunctionComponent<import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<any>>, import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<unknown>>, {
        label?: import("react").ReactNode;
        name: string;
        placeholder?: string | boolean | null | undefined;
    }>>> & {
        Component: import("react").ComponentType<Partial<import("uniforms").GuaranteedProps<any>>>;
        options: {
            initialValue?: boolean | undefined;
            kind?: "leaf" | "node" | undefined;
        } | undefined;
    })>;
    defaultComponentDetector: (props: import("uniforms").GuaranteedProps<unknown> & Record<string, any>, uniforms: import("uniforms").Context<unknown>) => import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | (import("react").FunctionComponent<import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<any>>, import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<unknown>>, {
        label?: import("react").ReactNode;
        name: string;
        placeholder?: string | boolean | null | undefined;
    }>>> & {
        Component: import("react").ComponentType<Partial<import("uniforms").GuaranteedProps<any>>>;
        options: {
            initialValue?: boolean | undefined;
            kind?: "leaf" | "node" | undefined;
        } | undefined;
    });
};
export default AutoField;
uniforms-antd/es5/AutoField.d.ts after - 432B
/// <reference types="react" />
export { AutoFieldProps } from 'uniforms';
declare const AutoField: ((rawProps: import("uniforms").AutoFieldProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
    componentDetectorContext: import("react").Context<import("uniforms").ComponentDetector>;
    defaultComponentDetector: import("uniforms").ComponentDetector;
};
export default AutoField;
uniforms-antd/es5/TextField.d.ts before - 11238B
import Input, { InputProps } from 'antd/lib/input';
import React, { Ref } from 'react';
import { FieldProps } from 'uniforms';
export declare type TextFieldProps = FieldProps<string, Omit<InputProps, 'onReset'>, {
    inputRef?: Ref<Input>;
}>;
declare const _default: React.FunctionComponent<import("uniforms").Override<import("uniforms").Override<Pick<InputProps, "hidden" | "color" | "size" | "style" | "multiple" | "disabled" | "height" | "translate" | "width" | "prefix" | "suffix" | "src" | "form" | "slot" | "title" | "pattern" | "children" | "list" | "step" | "id" | "name" | "onChange" | "placeholder" | "readOnly" | "value" | "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "max" | "maxLength" | "min" | "minLength" | "required" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "lang" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "prefixCls" | "allowClear" | "bordered" | "enterKeyHint" | "onPressEnter" | "addonBefore" | "addonAfter">, import("uniforms").GuaranteedProps<string> & {
    inputRef?: ((instance: Input | null) => void) | React.RefObject<Input> | null | undefined;
}>, import("uniforms").Override<Partial<import("uniforms").GuaranteedProps<string | undefined>>, {
    label?: React.ReactNode;
    name: string;
    placeholder?: string | boolean | null | undefined;
}>>> & {
    Component: React.ComponentType<import("uniforms").Override<Pick<InputProps, "hidden" | "color" | "size" | "style" | "multiple" | "disabled" | "height" | "translate" | "width" | "prefix" | "suffix" | "src" | "form" | "slot" | "title" | "pattern" | "children" | "list" | "step" | "id" | "name" | "onChange" | "placeholder" | "readOnly" | "value" | "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "max" | "maxLength" | "min" | "minLength" | "required" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "lang" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "prefixCls" | "allowClear" | "bordered" | "enterKeyHint" | "onPressEnter" | "addonBefore" | "addonAfter">, import("uniforms").GuaranteedProps<string> & {
        inputRef?: ((instance: Input | null) => void) | React.RefObject<Input> | null | undefined;
    }>>;
    options: {
        initialValue?: boolean | undefined;
        kind?: "leaf" | "node" | undefined;
    } | undefined;
};
export default _default;
uniforms-antd/es5/TextField.d.ts after - 358B
import Input, { InputProps } from 'antd/lib/input';
import { Ref } from 'react';
import { FieldProps } from 'uniforms';
export declare type TextFieldProps = FieldProps<string, Omit<InputProps, 'onReset'>, {
    inputRef?: Ref<Input>;
}>;
declare const _default: import("uniforms").ConnectedField<TextFieldProps, string | undefined>;
export default _default;

Surprisingly, an update of TypeScript broke connectField inference and forced me to explicitly state Props in all cases. It may be a breaking change type-wise but not necessarily, as it may be the case, that:

  • Previously inferred type was incorrect.
  • Someone already had this type parameter in place. As I checked, we actually do in a couple of projects.
    Therefore, I think we can release it as a semver-minor.

@radekmie radekmie added the Type: Feature New features and feature requests label May 6, 2021
@radekmie radekmie added this to the v3.5 milestone May 6, 2021
@radekmie radekmie requested review from Monteth and wadamek65 May 6, 2021 15:17
@codecov
Copy link

codecov bot commented May 6, 2021

Codecov Report

Merging #949 (e399788) into master (af399da) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e399788 differs from pull request most recent head 6cf6885. Consider uploading reports for the commit 6cf6885 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
- Coverage   98.82%   98.82%   -0.01%     
==========================================
  Files         202      202              
  Lines        3151     3144       -7     
  Branches      796      791       -5     
==========================================
- Hits         3114     3107       -7     
  Misses          1        1              
  Partials       36       36              
Impacted Files Coverage Δ
packages/uniforms-antd/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-bootstrap3/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-bootstrap4/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-bootstrap5/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-material/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-semantic/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-unstyled/src/AutoField.tsx 100.00% <ø> (ø)
packages/uniforms-antd/src/BoolField.tsx 100.00% <100.00%> (ø)
packages/uniforms-antd/src/DateField.tsx 100.00% <100.00%> (ø)
packages/uniforms-antd/src/ErrorField.tsx 100.00% <100.00%> (ø)
... and 96 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af399da...6cf6885. Read the comment docs.

@radekmie radekmie merged commit 06f0aa6 into master May 7, 2021
@radekmie radekmie deleted the improved-typings branch May 7, 2021 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features and feature requests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Ts error: Unused '@ts-expect-error' directive. TS2578
3 participants