简体   繁体   English

“tech”类型的参数不能分配给“PropsWithChildren”类型的参数<props> '</props>

[英]Argument of type '“tech”' is not assignable to parameter of type 'PropsWithChildren<Props>'

I'm getting an error when I try to test the function getProblemType.当我尝试测试 function getProblemType 时出现错误。 Argument of type '"tech"' is not assignable to parameter of type 'PropsWithChildren<Props>'. Below is the code for my component.下面是我的组件的代码。

interface Props {
  type: SupportType;
}

export function getProblemType(srType:SupportType):ProblemTypeEnum {
  switch (srType) {
    case "limit":
      return "LIMIT";
    case "account":
      return "ACCOUNT";
    default:
      return "TECH";
  }
}
const Auth: React.FC<Props> = (props) => {
  const problemType  = getProblemType(props.supportType);
  const supportValidate = apiCalls.callSupport(false, "123", userId, problemType, state.homeRegionName);
 return (<>....</>)
};
export default Auth;

and my test looks like below我的测试如下所示

describe("Auth tests", () => {
  let mock : Props;
  const runProblemTypeTest = (url: string, supportType: SupportType) => {
  }
  mount(
      <Auth supportType={supportType}>
        <div>TestChild</div>
      </Authorization>
    );
    expect(apiCalls).toHaveBeenCalledWith(
      false,
      "1234",
      "test",
      getProblemType(supportType),
      "homeRegion"
    );

  it("check getProblemType when support is tech", () => {
    mock.supportType = "tech";
    expect(getProblemType(mock.supportType)).toEqual("TECH");
  });
  
  it("check problem type passed to validate when problem type absent in the url", () => {
    mock.supportType = "tech";
    runProblemTypeTest("http://www.test.com", "tech");
  });
});

when I pass mock.supportType on getProblemType, I get below error Argument of type '"tech"' is not assignable to parameter of type 'PropsWithChildren<Props>'.当我在 getProblemType 上传递 mock.supportType 时,我得到以下错误Argument of type '"tech"' is not assignable to parameter of type 'PropsWithChildren<Props>'.

The test mistakenly uses default import instead of named.测试错误地使用默认导入而不是命名。 So getProblemType is assigned the component and expects to be passed props.因此getProblemType被分配了组件并期望被传递道具。 Hence the error.因此错误。 Fix by inserting braces:通过插入大括号来修复:

 import { getProblemType } from "components/Common/Authorization";

暂无
暂无

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

相关问题 类型 &#39;(props: RouteProps) =&gt; JSX.Element&#39; 不可分配给类型 &#39;PropsWithChildren<RouteProps> &#39; - Type '(props: RouteProps) => JSX.Element' is not assignable to type 'PropsWithChildren<RouteProps>' 参数类型不可分配给参数类型 - Argument type not assignable to parameter type 输入 '({ items }: PropsWithChildren<todoprops> ) => Element[]' 不可分配给类型 'FunctionComponent<todoprops> '</todoprops></todoprops> - Type '({ items }: PropsWithChildren<TodoProps>) => Element[]' is not assignable to type 'FunctionComponent<TodoProps>' '(props: ITableProps) =&gt; JSX.Element' 类型的参数不能分配给类型的参数...... - React HOC - Argument of type '(props: ITableProps) => JSX.Element' is not assignable to parameter of type … - React HOC “{...}”类型的参数不可分配给“Context”类型的参数<AuthProps> &#39; - Argument of type '{...}' is not assignable to parameter of type 'Context<AuthProps>' “() =&gt; Timeout”类型的参数不可分配给“number”类型的参数 - Argument of type '() => Timeout' is not assignable to parameter of type 'number' 类型参数不能分配给 BaseUI 类型的参数 - Argument of type is not assignable to parameter of type BaseUI 类型&#39;Element []&#39;的参数不能分配给类型&#39;Element&#39;的参数 - Argument of type 'Element[]' is not assignable to parameter of type 'Element' “字符串”类型的参数不可分配给“Blob”类型的参数 - Argument of type 'string' is not assignable to parameter of type 'Blob' null 类型的参数不可分配给 RadioGroupState 类型的参数 - Argument of type null is not assignable to parameter of type RadioGroupState
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM