Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template tag jsdoc not evaluated with function callback as parameter #11724

Closed
Thaina opened this issue Oct 19, 2016 · 4 comments
Closed

template tag jsdoc not evaluated with function callback as parameter #11724

Thaina opened this issue Oct 19, 2016 · 4 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Thaina
Copy link

Thaina commented Oct 19, 2016

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

image

image

As you could see. It seem like it only parse correctly when param is normal array. And fail with callback function as param

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Salsa labels Oct 19, 2016
@DanielRosenwasser
Copy link
Member

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.

@Thaina
Copy link
Author

Thaina commented Oct 19, 2016

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());

image

image

It seem like order of evaluation for salsa in typescript v2 was changed. So it cause problem on generic guess work

@mhegazy mhegazy added this to the TypeScript 2.1.5 milestone Dec 14, 2016
@sandersn
Copy link
Member

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!

@sandersn
Copy link
Member

Fix is up at #12982

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 21, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants