TypeScript 在JSX中,所有重载函数的无用且可怕的详细说明,

bweufnob  于 5个月前  发布在  TypeScript
关注(0)|答案(2)|浏览(63)
  1. 在基础中打开VS Code
  2. 打开文件 packages/core/components/Checkbox.jsx
  3. 转到第100行
  4. 进行更改
- <Label {...style} checked={checked} disabled={disabled}>
+ <Label style={style} checked={checked} disabled={disabled}>

观察错误信息:

No overload matches this call.
  Overload 1 of 2, '(props: Pick<Pick<Pick<DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "form" | ... 255 more ... | "htmlFor"> & { ...; }, "form" | ... 256 more ... | "htmlFor"> & Partial<...>, "form" | ... 256 more ... | "htmlFor"> & { ...; } & { ...; }): ReactElement<...>', gave the following error.
    Type '{ children: Element[]; style: any; checked: any; disabled: any; }' is not assignable to type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "form" | ... 255 more ... | "htmlFor"> & { ...; }, "form" | ... 256 more ... | "htmlFor"> & Partial<...>, "form" | ... 256 more ... | "htmlFor"> & { ...; } & { ...; }'.
      Property 'checked' does not exist on type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "form" | ... 255 more ... | "htmlFor"> & { ...; }, "form" | ... 256 more ... | "htmlFor"> & Partial<...>, "form" | ... 256 more ... | "htmlFor"> & { ...; } & { ...; }'.
  Overload 2 of 2, '(props: StyledComponentPropsWithAs<"label", any, {}, never>): ReactElement<StyledComponentPropsWithAs<"label", any, {}, never>, string | ... 1 more ... | (new (props: any) => Component<...>)>', gave the following error.
    Type '{ children: Element[]; style: any; checked: any; disabled: any; }' is not assignable to type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "form" | ... 255 more ... | "htmlFor"> & { ...; }, "form" | ... 256 more ... | "htmlFor"> & Partial<...>, "form" | ... 256 more ... | "htmlFor"> & { ...; } & { ...; }'.
      Property 'checked' does not exist on type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "form" | ... 255 more ... | "htmlFor"> & { ...; }, "form" | ... 256 more ... | "htmlFor"> & Partial<...>, "form" | ... 256 more ... | "htmlFor"> & { ...; } & { ...; }'.ts(2769)

rxztt3cl

rxztt3cl1#

这是否被认为是相同的错误?
http://www.typescriptlang.org/play/index.html#code/JYOwLgpgTgZghgYwgAgPIAczAPYgM7IDeAUMsiHALYQBcyeYUoA5gNzEC+xoksiKAJQh4ArgBswRZFx7R4SZAOzYwANThiRKQtOLEYIkAiy5kMAIwAKAJR0lK9ZojsDRkyDNW4UZnQZMQZltFYXEwF0NjHA8LS29fNExovGChUQkIt2jPOJ8Afj9GFmQAH0T3FLtQiSJSZGAYZFzmZABeVuRDABMIGFAILutasjIoCDARKA9CDnYyDmQIMTxtOtHxyZiAJmbrOd0ufUj3Mx34woCgqvTwo6zTGDOfOgwK1Orb1yiHp4T-YrKr2S7xuw2QYwmUyIs04QA

qxgroojn

qxgroojn2#

是的,我在使用https://github.com/ReactTraining/history/时遇到了这个问题。
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1f36fb3afd908ffa206570c4f0ecae4178f6944e/types/history/index.d.ts#L15-L16

push(path: Path, state?: HistoryLocationState): void;
push(location: LocationDescriptorObject<HistoryLocationState>): void;

push有两个重载,我传递了LocationDescriptor<S = LocationState> = Path | LocationDescriptorObject<S>;给它。但是当我传递LocationDescriptor给push方法时,它抛出了相同的错误。

相关问题