Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ulrichb opened this issue Dec 7, 2018 · 2 comments
Closed
Assignees
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed Fixed A PR has been merged for this issue

Comments

@ulrichb
Copy link

ulrichb commented Dec 7, 2018

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:

@ahejlsberg
Copy link
Member

This is a known and unfortunate design limitation. See comment here. We're thinking about ways to alleviate the issue.

@ulrichb
Copy link
Author

ulrichb commented Dec 7, 2018

@ahejlsberg Ah, okay. Didn't find that. Thanks for the link. I'll leave this issue open for discoverability.

@weswigham weswigham added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Dec 7, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Dec 8, 2018
@ahejlsberg ahejlsberg self-assigned this Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants