Typescript: Expected between 2 and 3 type arguments error when 2 arguments were given.

Created on 6 Aug 2018  路  2Comments  路  Source: microsoft/TypeScript

TypeScript Version: 3.1.0-dev.20180804


Search Terms:

  • Expected between 2 and 3 type arguments.
  • Styled components.

Code
I can't seem to replicate this in the TypeScript Playground, but I have replicated the issue with typescript@next. Unsure at this point if it's an issue with TypeScript or Styled Components, but it certainly doesn't look like it should be an issue with Styled Components.

Expected behavior:
When compiling I'd expect no errors for line 179 in styled components' type definition file.

export function isStyledComponent(target: any): target is StyledComponentClass<{}, {}>

Actual behavior:
When compiling we receive the following error for line 179 in styled components' type definition file in our CircleCI build for our lockfile maintenance pull request.

> tsc

node_modules/styled-components/typings/styled-components.d.ts:179:59 - error TS2707: Generic type 'StyledComponentClass<P, T, O>' requires between 2 and 3 type arguments.

179 export function isStyledComponent(target: any): target is StyledComponentClass

The error states that between 2 and 3 type arguments are required for StyledComponentClass, which is correct according to lines 55 to 69 in styled components' type definition file which are shown below. Since two type arguments were given it's not clear why this is a compiler error.

export interface StyledComponentClass<P, T, O = P>
  extends ComponentClass<ThemedOuterStyledProps<O, T>> {
  extend: ThemedStyledFunction<P, T, O>

  withComponent<K extends keyof JSX.IntrinsicElements>(
    tag: K
  ): StyledComponentClass<
    JSX.IntrinsicElements[K],
    T,
    JSX.IntrinsicElements[K] & O
  >
  withComponent<U = {}>(
    element: React.ComponentType<U>
  ): StyledComponentClass<U, T, U & O>
}

Related Issues
https://github.com/styled-components/styled-components/issues/1891

External

Most helpful comment

@ryansmith94 problem is the bugged string originally was

export function isStyledComponent(target: any): target is StyledComponentClass

when StyledComponentClass has been used w/o any arguments instead of expected 2 or 3.

So this is not a TS issue and it already has been fixed in the master branch of styled-components but not yet released.

All 2 comments

@ryansmith94 problem is the bugged string originally was

export function isStyledComponent(target: any): target is StyledComponentClass

when StyledComponentClass has been used w/o any arguments instead of expected 2 or 3.

So this is not a TS issue and it already has been fixed in the master branch of styled-components but not yet released.

Ah that's great, thanks @Ky6uk

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nitzantomer picture nitzantomer  路  135Comments

disshishkov picture disshishkov  路  224Comments

blakeembrey picture blakeembrey  路  171Comments

metaweta picture metaweta  路  140Comments

jonathandturner picture jonathandturner  路  147Comments