I had trouble coming up with a good name and search terms for this issue. It looks like it's triggering some heuristic that is misbehaving and is very strange. Please feel free to rename if you can come up with a better summary for it.
TypeScript Version: 3.3.1
Search Terms: mapvalues ternary side effect unused inference empty object type
Code
// Begin types from Lodash.interfaceDictionary<T>{[index: string]: T;}interfaceNumericDictionary<T>{[index: number]: T;}typeObjectIterator<TObject,TResult>=(value: TObject[keyofTObject],key: string,collection: TObject)=>TResult;typeDictionaryIterator<T,TResult>=ObjectIterator<Dictionary<T>,TResult>;// In lodash.d.ts this function has many overloads, but this seems to be the problematic one.functionmapValues<T,TResult>(obj: Dictionary<T>|NumericDictionary<T>|null|undefined,callback: DictionaryIterator<T,TResult>): Dictionary<TResult>{returnnullasany;}// End types from Lodash.interfaceFoo{foo: string;}interfaceBar{bar: string;}exportfunctionfooToBar(foos: Record<string,Foo>,): Record<string,Bar|null>{// The next line, despite being unrelated to the other two lines, causes them to fail.// Comment it out to see the function compile erroneously.//// This behavior only happens when `result` is used as an intermediate: if you return // the ternary directly, the function always compiles.//// I couldn't find another Lodash function for which this issue reproduced after sampling// a few. constwat=mapValues(foos,f=>f.foo);constresult=foos==null ? {} : mapValues(foos,f=>f.foo);// This line _should_ fail, because `result` is not the right type.returnresult;}Expected behavior: fails to compile without the const wat line present.
Actual behavior: only fails to compile when const wat is present.
Playground Link:link
Related Issues:
I had trouble coming up with a good name and search terms for this issue. It looks like it's triggering some heuristic that is misbehaving and is very strange. Please feel free to rename if you can come up with a better summary for it.
TypeScript Version: 3.3.1
Search Terms: mapvalues ternary side effect unused inference empty object type
Code
Expected behavior: fails to compile without the
const watline present.Actual behavior: only fails to compile when
const watis present.Playground Link:link
Related Issues: