codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Typechecking of Promises should be implemented in a different way #128

Closed facundocabrera closed 7 years ago

facundocabrera commented 8 years ago

Hey!

I found myself stuck having this issue, I highly recommend to change the snippet generated for Promise instance checking with something more "intelligent", maybe just doing a "thenable" check is enough.

What do you think?

phpnode commented 8 years ago

yes I totally agree, this was planned but didn't get around to it yet, fancy making a PR? The check should be something like:

input !== null && typeof input === 'object' && typeof input.then === 'function'
facundocabrera commented 8 years ago

I'll love to send a PR, but need to check where should I need to do change.

For now what I did was:

type Thenable = {
  then: Function
};

function () :Thenable {
... do something ...
}

And as you can imagine, Map, Set, WeakMap, and so on, can have similar scenarios. Is there any plan to define the interfaces for these types? This is something I'm little worry in order to be confident to use this project.

phpnode commented 8 years ago

I'd like to get to this in v4. The plan is to parse flow's .flowconfig to discover interface definitions in the same way that flow does, but it's a lot of work.

SpaceviewMob commented 8 years ago

I could also see it being valuable to check for the result value of the Promise, e.g. a Promise<string> could validate that it actually resolves to a string.

phpnode commented 7 years ago

This project is now deprecated in favour of https://codemix.github.io/flow-runtime which has much better support for Flow, I opened a corresponding issue here: https://github.com/codemix/flow-runtime/issues/3