Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof
備注: 元素隱式地具有“ 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);
});
};