From 72cb1f9b78dd10dc214c1b2b4f70ba1cfebc4476 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 21 Sep 2017 13:10:14 +0800 Subject: [PATCH] flow: teach type inference --- flow.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/flow.md b/flow.md index bdd548c3b..852687a65 100644 --- a/flow.md +++ b/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/) +### 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 ```js