大佬教程收集整理的这篇文章主要介绍了React Typescript 组件中缺少属性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
React 组件
import {input} from '@xxx/forms';
<input label="account name" name="account"/>
input.d.ts
import React,{ Ref } from 'react';
import { inputProps as UITKinputProps } from '@xxx/input';
import { WithStyles,Density } from '@xxx/theme';
import { FormFIEldProps as FormFIEldPropsType } from '../FormFIEld';
import { NecessityStyle } from '../types';
import styles from './styles';
export declare type inputProps = WithStyles<typeof styles> & UITKinputProps & {
name: string;
label?: string;
ID?: string;
Disabled?: boolean;
FormFIEldProps?: Omit<FormFIEldPropsType,'children' | 'name' | 'label'>;
required?: boolean;
necessityStyle?: NecessityStyle;
helperText?: string;
ref?: Ref<any>;
fullWIDth?: boolean;
density?: Density;
};
declare const Styledinput: React.ComponentType<Pick<React.PropsWithChildren<inputProps>,"required" | "Disabled" | "error" | "hIDden" | "dir" | "label" | "slot" | "style" | "Title" | "color" | "ref" | "children" | "onBlur" | "onChange" | "onsubmit" | "name" | "onFocus" | "defaultValue" | "ID" | "textAlign" | "translate" | "margin" | "classname" | "innerRef" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inList" | "prefix" | "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" | "onFocusCapture" | "onBlurCapture" | "onChangeCapture" | "onBeforeinput" | "onBeforeinputCapture" | "oninput" | "oninputCapture" | "onreset" | "onresetCapture" | "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" | "type" | "fullWIDth" | "autoFocus" | "value" | "inputProps" | "inputRef" | "Readonly" | "multiline" | "autoComplete" | "endAdornment" | "inputComponent" | "renderSuffix" | "rows" | "rowsMax" | "rowsMin" | "startAdornment" | "disableunderline" | "density" | "necessityStyle" | "helperText" | "cursorpositionOnFocus" | "emptyReadonlyMarker" | "highlightOnFocus" | "FormFIEldProps"> & import("@material-ui/styles").StyledComponentProps<"Disabled" | "input" | "root" | "Readonly" | "focused" | "multiline" | "inputMultiline" | "endAdornment" | "startAdornment" | "lowDensity" | "touchDensity" | "mediumDensity" | "highDensity" | "fIEld">>;
export { Styledinput as input };
<input />
的唯一必填字段是 name
。但是,编译器在抱怨:
输入 '{ name: string; }' 缺少类型 'Pick
如何在组件中声明 input 组件?
虽然您没有为 WithStyles
和 UITKInputProps
提供完整的类型定义,但我猜他们里面有很多必需的道具。因此,您的 InputProps
类型从这两种类型加上明确定义的带有必需 name
字段的道具中扩展为大量必需道具。因此错误。
如果您希望 InputProps
类型具有唯一的必填字段 name
,您可以将其定义为:
export declare type InputProps
= Partial<WithStyles<typeof styles>>
& Partial<UITKInputProps>
& {
name: string;
label?: string;
id?: string;
disabled?: boolean;
FormFieldProps?: Omit<FormFieldPropsType,'children' | 'name' | 'label'>;
required?: boolean;
necessityStyle?: NecessityStyle;
helperText?: string;
ref?: Ref<any>;
fullWidth?: boolean;
density?: Density;
};
以上是大佬教程为你收集整理的React Typescript 组件中缺少属性全部内容,希望文章能够帮你解决React Typescript 组件中缺少属性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。