template tag jsdoc not evaluated with function callback as parameter
Thaina opened this issue · 4 comments
I made function SortFilter like this
/**
* @param {T[]} arr
* @template T
*/
function ItIs(arr) // for test
{
return arr;
}
/**
* @param {T[]} arr
* @param {function(T):number} valuator
* @template T
*/
function SortFilter(arr,valuator)
{
return arr.map((item) => {
return { item: item,value: valuator(item) };
}).filter((pair) => Number.isFinite(pair.value)).sort((l,r) => {
return l.value - r.value;
}).map((pair) => pair.item);
}
And this is the result
As you could see. It seem like it only parse correctly when param is normal array. And fail with callback function as param
Interestingly, if you write
var x = SortFilter([1,2,3], undefined)
you'll get number[]
.
Additionally, with the following
var x = SortFilter([1,2,3], q => q)
If you request quick info on x
and then on q
, q
will correctly get the type number
(though x
will still have the type T[]
.
But if you reverse the order (request quick info on q
and then x
), then you will get type T[]
on x
and T
for q
.
Though this might be unrelated, it'd make for a good test case.
Talk about order of evaluation. I remembered this is used to work in 1.8-1.9
There is another bug I found that it may related. I like to make a chain promise with reduce
var prom = [0,1,2].reduce((promise,n) => promise.then(() => n),Promise.resolve());
It seem like order of evaluation for salsa in typescript v2 was changed. So it cause problem on generic guess work
The problem is that isSymbolInScopeOfMappedTypeParameter
doesn't know about JSDoc. This function skips instantiation for type parameters that aren't even in scope. Unfortunately, it thinks that JSDoc type parameters are not in scope!