Skip to content

Running a type through a mapped type loses polymorphic this type  #39204

@dragomirtitian

Description

@dragomirtitian

TypeScript Version: 4.0.0-dev.20200622

Search Terms: polymorphic this mapped type

Expected behavior: b.foo() returns B

Actual behavior: b.foo() returns A even though the tooltip on foo says it returns this

Related Issues: None

Code

interface A {
    foo(): this
}

interface B extends Pick<A, keyof A> {
    bar(): this
}

declare let b: B;
b.foo().bar() // error 
Output
"use strict";
b.foo().bar(); // error 
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions