Skip to content

Regression: something is wrong with type checking in dev.20180919 #27223

@qwertie

Description

@qwertie

TypeScript Version: Version 3.1.0-dev.20180919

Code

This code compiles in v3.0.3 but fails in 3.1.0-dev.20180919.

/** Represents a React/preact component with a state property and setState method. */
export type StatefulComponent<S> = {
  state: S, setState: (s: any /*Partial<S>*/) => any
};

export function f<This extends StatefulComponent<S>, S=This["state"]>(component: This): void
{
  if (Math.random()>0.5) f(component);
}

Expected behavior:

Compiles without error.

Actual behavior:

hold.ts:8:28 - error TS2345: Argument of type 'This' is not assignable to parameter of type 'StatefulComponent<This["state"]>'.
  Type 'StatefulComponent<S>' is not assignable to type 'StatefulComponent<This["state"]>'.
    Types of property 'state' are incompatible.
      Type 'S' is not assignable to type 'This["state"]'.

8   if (Math.random()>0.5) f(component);

Playground Link: No error in Playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions