TypeScript Version: 2.6.1
also tested and fails on 2.7.0
also tested and fails on 2.7.0-dev.20180119 (@next)
Code
typeMyType<T>={[KinkeyofT]: string|true|PromiseLike<string|true>};functionMapObject<T,TOut>(value: T,map: <KextendskeyofT>(value: T[K],key: K)=>TOut) : {[KinkeyofT] : TOut}{returnnullasany;}//MyFunction//2.5.3 compiles//2.6.1 do not compiles since ret variable is not compatible with the function return value//@next do not compiles since ret variable is not compatible with the function return valuefunctionMyFunction<T>(value: MyType<T>) : {[KinkeyofT] : Promise<string|undefined>}{consta=MapObject(value,x=>x);//B should be { [K in keyof T ]: Promise<string | undefined>}constb=MapObject(a,asyncx=>{//myVal type://(correct) 2.5.3: string | true//(incorrect) 2.6.1: { [K in keyof T]: MyType<T>[any] }[K]//(incorrect) @next: { [K in keyof T]: MyType<T>[any] }[K]constmyVal=awaitx;//ret type should be string | undefined//(correct) 2.5.3: string | undefined //(incorrect) 2.6.1: { [K in keyof T]: MyType<T>[any] }[K] | undefined//(incorrect) @next: { [K in keyof T]: MyType<T>[any] }[K] | undefinedconstret=myVal===true ? undefined : myVal;returnret;})returnb;}Expected behavior:
myVal variable inferred type to be string | true
ret variable inferred type to be string | undefined
The code should compile since the return value of the function type and the return expression is the same
Actual behavior:
myVal variable inferred type is { [K in keyof T]: MyType<T>[any] }[K]
ret variable inferred type is { [K in keyof T]: MyType<T>[any] }[K] | undefined
The code does not compile since the return type does not match the return expression
TypeScript Version: 2.6.1
also tested and fails on
2.7.0also tested and fails on
2.7.0-dev.20180119(@next)Code
Expected behavior:
myValvariable inferred type to bestring | trueretvariable inferred type to bestring | undefinedThe code should compile since the return value of the function type and the return expression is the same
Actual behavior:
myValvariable inferred type is{ [K in keyof T]: MyType<T>[any] }[K]retvariable inferred type is{ [K in keyof T]: MyType<T>[any] }[K] | undefinedThe code does not compile since the return type does not match the return expression