Skip to content

False positive assignment error with generics when using --strictBindCallApply #28900

@ulrichb

Description

@ulrichb

TypeScript Version: 3.3.0-dev.20181207

Search Terms: bind generic strict

Code

class SomeClass {

    constructor() {
        this.genericMethod = this.genericMethod.bind(this);
        
        // TS2322: Type '(callback: (p: {}) => {}) => void' is not
        // assignable to type '<T>(callback: (p: T) => T) => void':
        this.genericWithCallback = this.genericWithCallback.bind(this);
    }

    genericMethod<T>(p: T): void { }

    genericWithCallback<T>(callback: (p: T) => T): void { }
}

Compile with tsc TypeScriptIssue.ts --target es6 --strictBindCallApply

Expected behavior:
No compile error

Actual behavior:

error TS2322: Type '(callback: (p: {}) => {}) => void' is not assignable to type '<T>(callback: (p: T) => T) => void'.
  Types of parameters 'callback' and 'callback' are incompatible.
    Types of parameters 'p' and 'p' are incompatible.
      Type '{}' is not assignable to type 'T'.

Playground Link: (no --strictBindCallApply flag available)

Related issues:

Metadata

Metadata

Assignees

Labels

Design LimitationConstraints of the existing architecture prevent this from being fixedFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy