diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index 6398ee36d5..c04de160b0 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -261,7 +261,7 @@ export interface ThemedBaseStyledInterface } export type ThemedStyledInterface = ThemedBaseStyledInterface< - Extract extends never ? any : T + AnyIfEmpty >; export type StyledInterface = ThemedStyledInterface; @@ -271,16 +271,15 @@ export type BaseThemedCssFunction =

( ) => Array>>; export type ThemedCssFunction = BaseThemedCssFunction< - Extract extends never ? any : T + AnyIfEmpty >; // Helper type operators type Omit = Pick>; -type DiffBetween = Pick> & - Pick>; type WithOptionalTheme

= Omit & { theme?: T; }; +type AnyIfEmpty = keyof T extends never ? any : T; export interface ThemedStyledComponentsModule { default: ThemedStyledInterface; @@ -318,7 +317,7 @@ export type BaseWithThemeFnInterface = < WithOptionalTheme, T> >; export type WithThemeFnInterface = BaseWithThemeFnInterface< - Extract extends never ? any : T + AnyIfEmpty >; export const withTheme: WithThemeFnInterface; @@ -334,13 +333,10 @@ export type BaseThemeProviderComponent = React.ComponentClass< >; export type ThemeProviderComponent< T extends object -> = BaseThemeProviderComponent< - Extract extends never ? any : T ->; -export const ThemeProvider: ThemeProviderComponent; -// NOTE: this technically starts as undefined -// Also, this cannot be DefaultTheme as it breaks TypedComponents' assignability -export const ThemeContext: React.Context; +> = BaseThemeProviderComponent>; +export const ThemeProvider: ThemeProviderComponent>; +// NOTE: this technically starts as undefined, but allowing undefined is unhelpful when used correctly +export const ThemeContext: React.Context>; export const ThemeConsumer: typeof ThemeContext["Consumer"]; export interface Keyframes {