flow: teach type inference
This commit is contained in:
parent
e217dc3c9f
commit
72cb1f9b78
11
flow.md
11
flow.md
|
@ -26,6 +26,17 @@ Most of what you need to do is to simply add annotations to function arguments!
|
||||||
|
|
||||||
See: [flow.org docs](https://flow.org/en/docs/)
|
See: [flow.org docs](https://flow.org/en/docs/)
|
||||||
|
|
||||||
|
### Type inference
|
||||||
|
|
||||||
|
```js
|
||||||
|
function square (n: number) {
|
||||||
|
const result = n * n
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
|
`result` is inferred to be a number because `number * number` will result in a number. There's no need to give it annotations.
|
||||||
|
|
||||||
### Type aliases
|
### Type aliases
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
Loading…
Reference in New Issue