You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive assignment error with generics when using --strictBindCallApply #28900
classSomeClass{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)
Activity
ahejlsberg commentedon Dec 7, 2018
This is a known and unfortunate design limitation. See comment here. We're thinking about ways to alleviate the issue.
ulrichb commentedon Dec 7, 2018
Anders Hejlsberg (@ahejlsberg) Ah, okay. Didn't find that. Thanks for the link. I'll leave this issue open for discoverability.