Files
test-repo/tests/missing_annotation/infer.js
T
Christopher Chedeau cf45afba61 Add testing
- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases
- This creates snapshot tests using the pretty printer for all of them
- If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.
2016-12-23 19:51:53 +00:00

59 lines
1.2 KiB
JavaScript

/* @flow */
var Foo = {
a: function(arg) { // missing arg annotation
return arg;
},
b: function(arg) { // missing arg annotation
return {
bar: arg
};
},
c: function(arg: string) { // no return annotation required
return {
bar: arg
};
},
d: function(arg: string): {
bar: string
} {
return {
bar: arg
};
},
// return type annotation may be omitted, but if so, input positions on
// observed return type (e.g. param types in a function type) must come
// from annotations
e: function(arg: string) {
return function(x) { // missing param annotation
return x;
}
},
// ...if the return type is annotated explicitly, this is unnecessary
f: function(arg: string): (x:number) => number {
return function(x) { // no error
return x;
}
}
};
var Bar = {
a: Foo.a('Foo'), // no annotation required
// object property types are inferred, so make sure that this doesn't cause
// us to also infer the parameter's type.
b: Foo.b('bar'), // no annotation required
c: Foo.c('bar'), // no annotation required
d: Foo.d('bar'), // no annotation required
};
module.exports = Foo, Bar;