一旦我在接口中添加了方法的重载版本,我就会收到错误.但是,如果我把它放在现有版本之前,我就不会了.原因是什么?我在哪里可以获得更多关于这方面的信息?这是秩序的问题吗?还是别的什么?
interface Item {}
interface MyCache {
// set(key: string, item: Item): void;
// ^ uncomment the line and it works
set(record: Record<string, Item[]>): void;
// set(key: string, item: Item): void;
// ^ uncomment the line and you get the errors
}
interface State {
cache: Record<string, Item[]>;
}
function useCache<C>({
state,
cache,
}: {
state: { cache: C };
cache: { set: (cacheValue: C) => void };
}) {
const { cache: cacheValue } = state;
cache.set(cacheValue);
}
function doSomething(state: State, cache: MyCache) {
useCache({ state, cache });
// the errors ^ are ^ here
}