People can get a little carried away with "consistency" when reasoning about what TypeScript does/doesn't consider to be worthy of a warning. Today's example const obj = { ...x?.someObj } This sometimes spreads in an 'undefined'. Is that OK? Is it "inconsistent" if it is? 1/
-
Show this thread
-
If you wrote { ...undefined } Even though this is a no-op at runtime, it's definitely an error; this operation is meaningless and it would make no sense to do it unconditionally. People don't write code like this on purpose.
1 reply 0 retweets 1 likeShow this thread -
Normally for a union type, the rule is that any operation you do to T | U has to be valid for both T and U. So it seems like { ...x?.someObj } is a consistency violation because sometimes this evaluates as { ...undefined }
3 replies 0 retweets 2 likesShow this thread
Replying to @SeaRyanC
Depends how you define consistency? Seems like “undefined is only allowed as a spread value when in a union” seems like a consistent rule to me.
1:21 PM - 20 Mar 2020
0 replies
0 retweets
0 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 