|
|
|
|
|
by squiggleblaz
2476 days ago
|
|
The compiler should be capable of inferring the type as far as reasonably possible. But it should be an error to not specific the types of top level functions and class methods. This way, when you write const f = (a, b) => a + b
the compiler can tell you to write: const f => <T extends number|string>(a: T, b: T): T => a + b
or const f : <T extends number|string>(a: T, b: T) => T
= (a, b) => a + b
This would be effectively like GHC's typeholes, where the compiler will tell you what to write when you say f :: _
f a b = a <> b
except that rather than being an optional step by a developer, it's a mandatory standard.(Well, I don't think typescript infers that type for that function, but whatever it actually infers, that's what should be there in the error message.) |
|