Re:Java record pattern matching in JDK 19
by danachow on Saturday May 14, 2022 @03:06PM
(#31381258)
What I'm saying is that this:
is really not anything meaningfully different than this
or this
you can imagine a pseudo TypeScript language like this
Actual TypeScript merely allows you to elide the "as obj" and all it needs to trigger this is the "typeof obj === <string literal>" inside of an if expression. This can be done by a simple syntactic replacement, it doesn't require control flow analysis to get this specific feature.
But yes, if you have a more general computed expression, that would apply, but that was not the case you were stating.
Ie the variable isn't the issue (redefining in this case seems like a distinction without a difference)... However this does work in TS, which is a demonstration of CFA:
For what it's worth I think CFA is useful in TypeScript based on it at its core being a structural typed bandaid over JS, but I think these specific CFA type narrowing features are redundant in stronger typed languages.
[ Parent
| on HN ]
There are no comments on this comment yet.