-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug