Skip to content

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

Closed
@Thaina

Description

@Thaina

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

Activity

DanielRosenwasser

DanielRosenwasser commented on Oct 19, 2016

@DanielRosenwasser
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

Thaina commented on Oct 19, 2016

@Thaina
Author

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

added this to the TypeScript 2.1.5 milestone on Dec 14, 2016
sandersn

sandersn commented on Dec 16, 2016

@sandersn
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

sandersn commented on Dec 16, 2016

@sandersn
Member

Fix is up at #12982

added
FixedA PR has been merged for this issue
on Dec 21, 2016
locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @sandersn@DanielRosenwasser@Thaina@mhegazy

      Issue actions

        template tag jsdoc not evaluated with function callback as parameter · Issue #11724 · microsoft/TypeScript