Hacker Newsnew | past | comments | ask | show | jobs | submit | jiangmy's commentslogin

Thanks for the bug reporting.

I have deployed a new version on the server to get this fixed!


Bug reporting?

I was only playing around, not understanding what this thingy is actually doing. :-)

I still don't know as you didn't explain anything.

Is there maybe a paper or something I could read?


Thank you all for sharing constructive thoughts and concerns.

I have written more FAQs on the website to make it more clear that what you can do with ESInfer. Plus, a `Comparison to Typescript` thread on the discussions repo on Github.

https://github.com/ESInfer/discus/discussions/1

And I'm planning to write more articles shortly.


Good One! There are two issues here:

1. Tuple or Array? The inferred type will be different depending on that decision.

Currently, I go for the Array one, so if you remove the `a[0].length` line, you will see `a` be inferred as `[string|number]`. But this will change if I think about this more thoroughly. What are your thoughts?

2. const/let constrain, constexpr, `if guarding,` and some internal methods are not implemented yet, so this is a false negative. But indeed will do!


Thank you for clarifying and providing the use case. It makes total sense to me! I'm adding this to my to-do list.

There can be many potential use cases, such as providing typing information to the IDE's LSP, ejecting them directly to the code as you suggested, integrating them into the CI process, etc.

I'm very open to providing all those possibilities, and there's no reason to limit how you use the typing information when you possess them automatically.


Thank you for sharing that great work! It's more like a dependent-type plug-in to typescript to me, if I understand it correctly.

ESInfer and Ezno work on different layers, in my opinion. ESInfer provides a general ability to type-check code, yet Ezno improves a type system by adding the dependent type support. Ezno can work on top of typescript and could work with ESInfer, right? An easy way to do this is to use ESInfer to generate typescript annotations and then pass it to Ezno.


Actually Ezno wants to do what you're saying as well, the general ability to type-check code, not just add dependent types on top. Their website has some more examples.

See also, Hegel, which also wants to statically type check JS without TS necessarily. Looks like this space is heating up!

https://hegel.js.org/

https://news.ycombinator.com/item?id=33162275


Hype up, Dude!

Very glad to see so many afford to make javascript a better language there! I played it around, and I found Hegel seems not to support dynamic features like modifications of objects or prototypes. And this is the real difficulty of implementing a sound and complete type system to a dynamic script language like javascript.

Can you share if they have any plans for that?

https://hegel.js.org/try#GYVwdgxgLglg9mABFApgZygCgIYEpEDeAUI...

https://hegel.js.org/try#MYewdgzgLgBCMF4YG8CGAuFAjTBGAvvgNwB...


I'm not affiliated with Hegel so I wouldn't know, maybe try contacting them directly via HN or their website.


Yes, I did not do the paperwork well enough. I'm writing more articles and adding more examples on the website in the following days.

As a brief reply here, it provides the ability to do statical type inference for javascript without writing additional code. With this ability, libraries or editors can perform better on code assistant/suggestion, linting, statical analysis, annotation generation for or not for typescript/flow, and so on.


The difficulty comes from how dynamic language features you support & how accurate the type is inferred. Both in typescript and flow, you need to write annotations/comments to help the compiler perform well.

ESInfer is doing it all statically and without additional stuff needed. You can try it out on the playground section at the bottom of the homepage. Would be glad if there is any feedback :)


> you need to write annotations/comments to help the compiler perform well.

That's not true of either AFAIK. Annotations help, but it can still catch things without them like:

   function x() { return "x"; }
   x() - 15; // Cannot perform arithmetic operation because string [1] is not a number.


> Both in typescript and flow, you need to write annotations to help the compiler perform well.

For Flow, that's true only in the most literal sense. Flow has excellent inference and can get a lot done without the user writing any annotations.


Thanks for your reply, and sorry for the confusion!

1. I replaced the GitHub link with a direct link now. Because it is still in the very early stage, the repo is only open for discussions like feature requests, using feedback, etc. 2. The main point is to do type check & annotation generation all automatically without one single line of additional code needed, which both flow nor typescript cannot achieve at present. 3. I'd like annotations to tip me on the type and to let the editor give me code suggestions based on them; however, I do not want to write them manually. 4. As for how to get type errors clear enough without learning, I'm doing it by avoiding using PL/type-system-related terms during the entire process. For example, `let a = 1; a = '1';` will raise an error that says `expecting number but got string.` to tell the user with easy to understand the sentence. For more complicated situations, like overloading mismatch, please experiment by the playground at the bottom of the homepage. (very sorry, I do not know how to write markdown on HN). Any feedback or thoughts on that is very welcome! 5. For the inferring result like `t547061|string` you pointed out. Yes, I agree that it's annoying. I will simplify the outcomes for the sake of readability over strictly correctness. But the top priority is still to add more ES6+ features if I think correctly.

Thank you again for the detailed feedback, and I apologize for any unclear caused. It's still early, and feedback like this is more than welcome. Thank you!


> avoiding using PL/type-system-related terms...tell the user with easy to understand the sentence.

What I meant by “making type errors clear” wasn’t so much the text of the error messages, but rather making the cause of the error more obvious. Here’s a very simplified example of the sort of thing I mean:

  function foo() {return '1.2'}
  const bar = foo() + 1
  const baz = bar.toFixed()
ESInfer complains on line 2, and TypeScript on line 3 (I guess it understands that `+` will coerce the type), but from my perspective the mistake is on line 1, where I forgot parseFloat(). Without annotations, the problem manifests as individual errors somewhere downstream of every call site; if I annotate foo() as returning a number, the type checker will immediately point me at the problem. In fact when I get a type error from tsc that I don’t immediately understand, my first step is usually to start scattering annotations around to help it narrow down where its take on the situation differs from mine.

Basically, neither ESInfer nor TypeScript give me great diagnostics for this code as-is, but TS lets me have a ‘conversation’; it has the tools I need to help it help me find the problem. ESInfer (in my admittedly cursory understanding) seems like it’s missing that ability; I can imagine a heuristics that would help it better explain the situation (e.g. showing the entire data flow that lead to a mismatch, rather than claiming the error is at a single point) but I haven’t thought about it very much so I was wondering if you had any particular ideas around this situation.

(Incidentally, you can find the syntax for HN comments at <https://news.ycombinator.com/formatdoc>. It’s linked from the FAQ, which is itself linked at the bottom of the page, though that’s not very obvious.)


  foo() + 1
ESInfer complains about this because you are adding a string with a number, which sometimes will result in an unexpected value in runtime, and you hardly find it out. So ESInfer, on purpose, disallows this kind of type casting automatically.

As for the error message:

> expecting possible candidates all failed: candidate number failed: expecting number but got string. candidate string failed: expecting string but got number. but got number.

It's saying two possible situations: #1 number + number and #2 string + string are all failed, which is precisely the error. However, this may be a lack of readability if someone is the first time using ESInfer. I'll write some wikis on how to read error messages efficiently as a starting point and, finally and hopefully, evolve a better error reporting system.

So if you ask me how to deal with this kind of code with ESInfer, I'd suggest making the compiler happy by converting the string to a number or the number to a string.

(BTW, try to use the format as suggested, hope it works :D)


I think the parent is raising the point that knowing that there's a problem is only half of the issue you need to solve. Being able to assert that certain types only appear in certain places is still important: if I pass the wrong type as a function argument, I don't know whether there's a bug somewhere upstream where that data came from, or whether there's a bug in the function where I'm using a parameter incorrectly. Or if I'm not returning where I should be, or returning where I shouldn't be.


Did you mean something like an error stack?

That'll be significantly helpful if the last error is not apparent enough to solve the error. I'll investigate this and see if there's any performance impact on the inferring process.


TypeScript can infer all the types but it still requires the coder to specify types in certain places because of the exact issue that is being shown here.

The types create an API contract that keeps errors localized. ESInfer raises an error at the call site, which is harder to understand what is going on. Also, lack of types will cause the API contract to suddenly change in unexpected ways.

I commend you for creating ESInfer, but there is a reason this approach is usually not taken.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: