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

Promises? #65

Closed trueter closed 8 years ago

trueter commented 8 years ago

Promise support would be great:

TypeError: Function 'loadCases' return value violates contract, expected Promise got Promise
phpnode commented 8 years ago

please could you post a reduced example which triggers this error?

trueter commented 8 years ago

Putting together the example I noticed a likely conflict between my global Promise implementation and a custom Promise that is being used by the package returning the Promise. I didn't find Promise being used in the examples so I anticipated it wasn't supported. Maybe one could add a warning hinting towards Object.keys(Promise) or another way of differentiating between these constructors. Issue can be closed.

phpnode commented 8 years ago

you can use something like this to cover both cases:

type Thenable<Success,Failure> = {
  then: (resolve?: (result: Success) => any, reject?: (result: Failure) => any) => Thenable
}

function someAsyncFunction (): Thenable<string> {
  return Promise.resolve("hello world");
}

It won't get typechecked yet though unfortunately.

trueter commented 8 years ago

Still stuck on Babel 5 :( - but looking forward to try that going forward!