简体   繁体   English

类型'IntrinsicAttributes & UserSelectProps & { children?: ReactNode; 上不存在属性'isMulti' }'.ts(2322)

[英]Property 'isMulti' does not exist on type 'IntrinsicAttributes & UserSelectProps & { children?: ReactNode; }'.ts(2322)

I have a component which looks like so:我有一个看起来像这样的组件:

      <Controller
        name="members"
        control={control}
        rules={{ required: true }}
        render={({ field }) => (
          <UserSelect
            accountId={accountId}
            label="Project Members"
            isMulti
            {...field}
          />
        )}
      />

and it is giving me the following TS error (red squiggly on isMulti ):它给了我以下 TS 错误( isMulti上的红色波浪):

Type '{ onChange: (...event: any[]) => void; onBlur: Noop; value: any; name: "members"; ref: RefCallBack; accountId: string; label: string; isMulti: true; }' is not assignable to type 'IntrinsicAttributes & UserSelectProps & { children?: ReactNode; }'. Property 'isMulti' does not exist on type 'IntrinsicAttributes & UserSelectProps & { children?: ReactNode; }'.ts(2322)

full component can be seen here:https://gist.github.com/pivcec/ea9714410f2baaaf9600a28091e9f6b7完整的组件可以在这里看到:https://gist.github.com/pivcec/ea9714410f2baaaf9600a28091e9f6b7

UserSelect component can be seen here:https://gist.github.com/pivcec/cb2645bf672324f990b27f6cd597dfcc UserSelect组件可以在这里看到:https://gist.github.com/pivcec/cb2645bf672324f990b27f6cd597dfcc

If you want to extend another component you can just intersect the props of Select.如果你想扩展另一个组件,你可以与 Select 的 props 相交。 I believe this is from react-select , but the simplest way to it would be like so:我相信这是来自react-select ,但最简单的方法是这样的:

type UserSelectProps = {
  accountId: string;
  label: string;
} & Parameters<typeof Select>[0];
// need to index 0, since that is props, 1 is context

Also react.forwardComponent is a generic component so the correct pattern would be something like this: react.forwardComponent 也是一个通用组件,所以正确的模式应该是这样的:

const UserSelect = React.forwardRef<UserSelectProps["ref"], Omit<UserSelectProps, "ref>">((props, ref) => {
  //...
})
// the first type parameter is the refType and the second is the propsType

IIRC react-select props type is generic, so this might be more useful like so: IIRC react-select道具类型是通用的,所以这可能更有用,如下所示:

import { GroupBase } from "react-select";

type UserSelectProps<
  Option = unknown,
  IsMulti extends boolean = false,
  Group extends GroupBase<Option> = GroupBase<Option>
> = {
  accountId: string;
  label: string;
  // This requires TS4.7^ VVV, instantiation expression
} & Parameters<typeof Select<Option, IsMulti, Group>[0];

// Since you didn't provide a sandbox I just wrote this of the top of my head,
// so this may or may not work...
const UserSelect = React.forwardRef(...) as <
  Option = unknown,
  IsMulti extends boolean = false,
  Group extends GroupBase<Option> = GroupBase<Option>
>(props: UserSelectProps<Select, IsMulti, Group>) => JSX.Element

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MUI v5 属性“fullWidth”在类型“IntrinsicAttributes &amp; { theme: Theme;”上不存在。 } &amp; { 孩子?:ReactNode; }&#39;。 TS2322 - MUI v5 Property 'fullWidth' does not exist on type 'IntrinsicAttributes & { theme: Theme; } & { children?: ReactNode; }'. TS2322 属性不存在于类型 'IntrinsicAttributes & { children?: ReactNode; }' - Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }' &#39;IntrinsicAttributes &amp; IntrinsicClassAttributes 类型上不存在属性<DatePicker> &amp; Readonly&lt;{ children?: ReactNode; }&gt; ...&#39; - Property does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<DatePicker> & Readonly<{ children?: ReactNode; }> …' 类型'IntrinsicAttributes &amp; PhoneInputProps &amp; { children?: ReactNode; 上不存在属性'ref' } - Property 'ref' does not exist on type 'IntrinsicAttributes & PhoneInputProps & { children?: ReactNode; } 类型“IntrinsicAttributes &amp; TableProp”.ts(2322) 上不存在属性“prop” - Property 'prop' does not exist on type 'IntrinsicAttributes & TableProp'.ts(2322) 类型“IntrinsicAttributes”上不存在属性“onSubmit”.ts(2322) - Property 'onSubmit' does not exist on type 'IntrinsicAttributes'.ts(2322) 类型“IntrinsicAttributes”上不存在属性“isOpen”。 ts(2322) - Property 'isOpen' does not exist on type 'IntrinsicAttributes. ts(2322) "<i>TypeScript: Property &#39;data&#39; does not exist on type &#39;{ children?: ReactNode;<\/i> TypeScript:类型&#39;{ children?:ReactNode;上不存在属性&#39;data&#39;<\/b> <i>}&#39;.<\/i> }&#39;。<\/b> <i>ts(2339)<\/i> ts(2339)<\/b>" - TypeScript: Property 'data' does not exist on type '{ children?: ReactNode; }'. ts(2339) 非常简单的 MWE,typescript 错误 TS2322 (...) 不能分配给类型 'IntrinsicAttributes &amp; Props &amp; { children?: ReactNode; }' - Very simple MWE, typescript error TS2322 (…) not assignable to type 'IntrinsicAttributes & Props & { children?: ReactNode; }' 重构对Typecript的反应会导致错误属性&#39;readOnly&#39;在类型&#39;IntrinsicAttributes&InputProps&{children?:ReactNode; }” - Refactoring React to Typescript causes error Property 'readOnly' does not exist on type 'IntrinsicAttributes & InputProps & { children?: ReactNode; }'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM