Closed
Description
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: