我正在使用测试库+i18next,并试图将翻译传递到测试库的查询方法中,但遇到了类型错误.但是,如果我将translate函数的结果声明为变量,则效果很好.也许这是出于设计,或者这两个库中的某个库中的类型出了问题?
请参见CodeSandbox here.
import { screen } from "@testing-library/dom";
import i18n from "i18next";
// This works
const translation = i18n.t("my.translation.string");
screen.getByText(translation);
// This does not:
// Argument of type 'TFunctionResult' is not assignable to parameter of type 'Matcher'.
// Type 'undefined' is not assignable to type 'Matcher'.
screen.getByText(i18n.t("my.translation.string"));