Should narrowing be applied on initial assignment? #232
Unanswered
KotlinIsland
asked this question in
Ideas
Replies: 1 comment 1 reply
-
here's a better example of when this behavior is annoying in typescript. when i explicitly specify the type as being wider, the compiler shouldn't ignore me: let foo: boolean = false
const changeFoo = () => {
foo = true
}
declare const condition: boolean
if (condition) {
changeFoo()
}
if (foo) {
foo //never
} perhaps it could be argued that it should behave like this for |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It can be frustrating is certain circumstances:
And forces you to write code that you normally wouldn't:
counterpoint:
I guess the question is: should the explicit type annotation act like a cast, or an upper bound?
Beta Was this translation helpful? Give feedback.
All reactions