Skip to content

Expected between 2 and 3 type arguments error when 2 arguments were given. #26226

@ryasmi

Description

@ryasmi

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
styled-components/styled-components#1891

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions