Wilson Mendes
@willmendesneto
Google Developer Expert Web Technologies
parametric types compatible
* if the type to assign from has a more special type parameter
Expressive
Easy to add, easy to remove
// Typescript
function foo(num: number) {
if (num > 10) {
return 'cool';
}
}
// It works!
const result: string = foo(100);
console.log(result.toString());
// It doesn't work
console.log(foo(1).toString());
// error at runtime
"Cannot read property 'toString' of undefined"
// Flow
function foo(num: number) {
if (num > 10) {
return 'cool';
}
}
// error: call of method `toString`.
console.log(foo(100).toString());
// Error:
"Method cannot be called on possibly null value"
// Flow usage
// Initialize your project
flow init
// Start background process
flow
// @flow
// test.js
function foo(x: ?number): string {
if (x) {
return x;
}
return "default string";
}
test.js:5
5: return x;
^
number. This type is incompatible with the
expected return type of
3: function foo(x: ?number): string {
^^^^^^ string
https://goo.gl/E7Ffzr
Wilson Mendes
@willmendesneto
Google Developer Expert Web Technologies