Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conditional types works incorrectly when generics with constraints #24190

Copy link
Copy link
@PomanoB

Description

@PomanoB
Issue body actions

TypeScript Version: 2.8.1, 2.9.0-dev.20180516

Search Terms: Conditional Types, generics

Code
strictFunctionTypes: true

type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;

interface Interface1
{
}

class Class1<T extends Interface1>
{
    private prop1: NonFunctionProperties<T>|null = null;

    public method1(): Class1<Interface1>
    {
        return this; // <- error TS2322
    }
}

Expected behavior:
No error

Actual behavior:

Error:(15, 9) TS2322: Type 'this' is not assignable to type 'Class1<Interface1>'.
  Type 'Class1<T>' is not assignable to type 'Class1<Interface1>'.
    Type 'Interface1' is not assignable to type 'T'.

Playground Link:
Need to enable strictFunctionTypes in Options
Playground

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.