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

Tern does not infer types through promises. #486

Closed
mseddon opened this issue Jan 22, 2015 · 7 comments
Closed

Tern does not infer types through promises. #486

mseddon opened this issue Jan 22, 2015 · 7 comments

Comments

@mseddon
Copy link

mseddon commented Jan 22, 2015

Using either Promise or Q, tern fails to infer the type of the success handler arguments. I wouldn't say this is a limitation of the tern type inferencer, but it seems like a good candidate for a plugin. Before I look too far into implementing one I was wondering:

a) does such a plugin exist?
b) is this possible with a plugin?
c) how much pain would be involved implementing such a plugin?

And perhaps, more abstractly:
d) is there a central location where developers contribute their tern plugins?

@angelozerr
Copy link
Contributor

a) does such a plugin exist?

Promise is for ECMAScript6. Today tern provides only ecma5.json

I have created a PR for ecma6.json #475

But it's very basic. I think Promise should be improved https://github.com/marijnh/tern/pull/475/files#diff-86d0e1883fb47a3188ad9f50734bc5deR465

b) is this possible with a plugin?

here it's a JSON Type Definition. I think Promise should be improved with custom inference function (infer.registerFunction).

d) is there a central location where developers contribute their tern plugins?

No but I have created this issues #424 We would like to provide a plugins.json which list the whole tern plugins.

I try to integrate tern plugins see https://github.com/angelozerr/tern.java/wiki/Getting-Started#tern-modules

To search tern plugins today, you can use those 2 urls :

@marijnh
Copy link
Member

marijnh commented Jan 22, 2015

Patch 57cf35f adds some magic to the definition of Promises in ecma6.json to make Tern mostly able to see through them, as far as result values are concerned. Let me know whether that works for you (you'll have to include the ecma6 defs to get it).

@mseddon
Copy link
Author

mseddon commented Feb 16, 2015

Yes, this is exactly the sort of thing I'm looking for 👍

If I get some time, I will attempt a Q plugin based around this.

@mseddon mseddon closed this as completed Feb 16, 2015
@othree
Copy link
Collaborator

othree commented Mar 23, 2015

I like to add fetch def file.
But I don't know how to assign the fulfill value of returned Promise in def file.
Here is what I expect:

"fetch": {
  "!type": "fn(url: string) -> +Promise[value=string]"
 }

(fulfill string is just for test)
I copy the return type format from Promise.resolve.
But the function parameter in then is still ?
Is it possible to given a specified fulfill value for promise in def file now?

marijnh added a commit that referenced this issue Mar 25, 2015
Combine the computed type parser and the static type parser
so that these actually parse the same language. Also removes
the need for guessing that kind of return type we are getting
ahead of time.

Issue #486
@marijnh
Copy link
Member

marijnh commented Mar 25, 2015

@othree That was a type parser issue. Patch 0958506 solves it.

@othree
Copy link
Collaborator

othree commented Mar 26, 2015

Thanks @marijnh

It looks work great but still have some problem.
I complete the fetch.json file.
And use it with following codes:

fetch().then(function(res) {
  res;
  res.blob().then(function (bbb) {
    bbb
  });
});

The first strange behavior I found is that bbb is not a blob object.
So I use TernType to inspect.
And it shows res is ArrayBuffer|string, not Response.
But res did have method and properties of Response.
bbb is similar as res.

@othree
Copy link
Collaborator

othree commented Jul 13, 2015

Finally I got this solved.
I forgot to include ecma6 in my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants