redoc/typings/styled-patch.d.ts

52 lines
1.9 KiB
TypeScript
Raw Normal View History

import * as styledComponents from 'styled-components';
// Styled components typings for using babel-plugin BEFORE typescript
declare module 'styled-components' {
2018-10-18 11:48:17 +03:00
type Attrs<P, A extends Partial<P>, T> = {
[K in keyof A]: ((props: ThemedStyledProps<P, T>) => A[K]) | A[K]
};
type KeyofBase = keyof any;
type Diff<T extends KeyofBase, U extends KeyofBase> = ({ [P in T]: P } & { [P in U]: never })[T];
type DiffBetween<T, U> = Pick<T, Diff<keyof T, keyof U>> & Pick<U, Diff<keyof U, keyof T>>;
interface ThemedStyledFunction<P, T, O = P> {
// adding "| string[]" for transpileTemplateLiterals and similar below
(
strings: TemplateStringsArray | string[],
2018-10-18 11:48:17 +03:00
...interpolations: Array<Interpolation<ThemedStyledProps<P, T>>>
): StyledComponentClass<P, T, O>;
2018-10-18 11:48:17 +03:00
<U>(
strings: TemplateStringsArray | string[],
2018-10-18 11:48:17 +03:00
...interpolations: Array<Interpolation<ThemedStyledProps<P & U, T>>>
): StyledComponentClass<P & U, T, O & U>;
2018-10-18 11:48:17 +03:00
attrs<U, A extends Partial<P & U> = {}>(
attrs: Attrs<P & U, A, T>,
): ThemedStyledFunction<DiffBetween<A, P & U>, T, DiffBetween<A, O & U>>;
// adding "withConfig" for transpileTemplateLiterals
withConfig(config: any): ThemedStyledFunction<P, T, O>;
}
2018-10-18 11:48:17 +03:00
export interface BaseThemedCssFunction<T> {
(
strings: TemplateStringsArray | string[],
...interpolations: SimpleInterpolation[]
): InterpolationValue[];
<P>(
strings: TemplateStringsArray | string[],
2018-10-18 11:48:17 +03:00
...interpolations: Array<Interpolation<ThemedStyledProps<P, T>>>
): Array<FlattenInterpolation<ThemedStyledProps<P, T>>>;
}
interface ThemedStyledComponentsModule<T> {
keyframes(
strings: TemplateStringsArray | string[],
...interpolations: SimpleInterpolation[]
2018-10-18 11:48:17 +03:00
): Keyframes;
createGlobalStyle<P = {}>(
strings: TemplateStringsArray | string[],
2018-10-18 11:48:17 +03:00
...interpolations: Array<Interpolation<ThemedStyledProps<P, T>>>
): GlobalStyleClass<P, T>;
}
}