Flow: Type Inference issue

Created on 21 Jan 2018  路  3Comments  路  Source: facebook/flow

In comparison with TypeScript, Flow doesn't catch these errors:

let n = 0
let s = "S"

test(n) // ok
// TypeScript only errors:
test(s)
n += s

let s2 = String()
let n2 = n // inherit type Number
test(n2)  // ok
// TypeScript only errors:
test(s2) 
n2 += s2

function test(n = 0) {}

Why? Is it ideology-based decision?

question

Most helpful comment

Since you didn't specifically annotate the test function, flow bases its inference off of the types with which you call it. Flow infers your test function to have the type:

(n?: number | string) => void

All 3 comments

Since you didn't specifically annotate the test function, flow bases its inference off of the types with which you call it. Flow infers your test function to have the type:

(n?: number | string) => void

This probably can be closed.
/cc @vkurchatkin

Type inference not working: We can close this :laughing:

Was this page helpful?
0 / 5 - 0 ratings