你将如何正确声明一个类型?
interface MediaQueryProps {
[key: string]: number;
}
const size: MediaQueryProps = {
small: 576,
medium: 768,
large: 992,
extra: 1200
};
export default Object.keys(size).reduce((acc, cur) => {
acc[cur] = `(min-width: ${size[cur]}px)`;
return acc;
}, {});
Run Code Online (Sandbox Code Playgroud)
acc[cur]
抱怨是因为
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在不使用任何类型的情况下为此声明类型吗?
typescript ×1