From 17133af0561a8ccc068b415572bec3649a182f90 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Thu, 25 Oct 2018 22:53:23 -0700 Subject: [PATCH 1/2] [styled-components] Fix #30042 - allow `attrs`'s `A` type parameter to accept exceed properties --- types/styled-components/index.d.ts | 2 +- types/styled-components/test/index.tsx | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index c6210edf91..023274bf2a 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -82,7 +82,7 @@ export interface ThemedStyledFunction { strings: TemplateStringsArray, ...interpolations: Array>> ): StyledComponentClass

; - attrs = {}>( + attrs & { [others: string]: unknown; } = {}>( attrs: Attrs

, ): ThemedStyledFunction, T, DiffBetween>; } diff --git a/types/styled-components/test/index.tsx b/types/styled-components/test/index.tsx index 8adfb03307..7f2197389f 100644 --- a/types/styled-components/test/index.tsx +++ b/types/styled-components/test/index.tsx @@ -312,6 +312,12 @@ const AttrsInput = styled.input.attrs({ padding: ${props => props.padding}; `; +// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/30042 +const AttrsWithOnlyNewProps = styled.h2.attrs({ as: 'h1' })` + color: ${props => props.as === 'h1' ? 'red' : 'blue'}; + font-size: ${props => props.as === 'h1' ? 2 : 1}; +`; + /** * component type */ From b383c0c873f715cbd36a8a4b218cc705964d0cc3 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Thu, 25 Oct 2018 23:09:09 -0700 Subject: [PATCH 2/2] fix TS 2.9 error --- types/styled-components/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index 023274bf2a..f436b8d490 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -82,7 +82,7 @@ export interface ThemedStyledFunction { strings: TemplateStringsArray, ...interpolations: Array>> ): StyledComponentClass

; - attrs & { [others: string]: unknown; } = {}>( + attrs & { [others: string]: any; } = {}>( attrs: Attrs

, ): ThemedStyledFunction, T, DiffBetween>; }