Based on https://tobbelindstrom.com/blog/how-to-create-a-breakpoint-mixin-with-styled-components/ I'm trying to do the same thing in TypeScript but I'm failing to type this function.
import { css } from 'styled-components';
import { breakpoints } from './_variables';
export const respondTo = Object.keys(breakpoints).reduce(
(accumulator, label) => {
accumulator[label] = (...args) => css`
@media (min-width: ${breakpoints[label]}) {
${css(...args)};
}
`;
return accumulator;
},
{}
);
I tried something like this:
export const respondTo = Object.keys(breakpoints).reduce<Record<string, Function>>(
(accumulator, label) => {
accumulator[label] = (...args: Array<String>) => css`
@media (min-width: ${breakpoints[label]}) {
${css(...args)};
}
`;
return accumulator;
},
{}
);
but it keeps throwing errors. Right now, it gives me
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 '{}'. TS7053
at breakpoints[label]
.