作者:小忠 | 来源:互联网 | 2024-10-15 13:47
备注:元素隐式地具有“any”类型,因为类型“string”的表达式不能用于索引类型“typeofimport(“xxx”)解决办法mock.tsexportfunctiontex
备注: 元素隐式地具有“ any”类型,因为类型“ string”的表达式不能用于索引类型“ typeof import(“xxx”)
解决办法
mock.ts
export function text(): boolean {
return false;
}
export function setAasd(): string {
return "asdgjhkj";
}
request.ts
interface MockIndex {
text: "text";
}
import * as Mock from "@/api/Mock.ts";
const request = (MockIndex: keyof MockIndex) => {
// 模拟异步请求数据
return new Promise((resolve) => {
setTimeout(() => {
resolve(Mock[MockIndex]);
}, 100);
});
};