Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Well, it is a Microsoft language - so naturally it has some quirks. You can use an intermediate variable to help the compiler.
-
h3rp1d3v5232y@Oktokolo Checked the latest version. The intermediate variable approach at the top will show as an error. The only walkaround now is to use Enum.
https://codesandbox.io/s/... -
I would assume (without checking) that it has more to do with the fact that typescript transpiles to JavaScript.
Transpiling imposes certain kind of restrictions - as is mentioned many times thoughout the docs, Typescript **should** be as close to JS as possible.
It isn't an independent language, it's just a lot of wrapping package around JS (aka the box full of excrements and other nasty stuff).
I'd guess that the AST of TS is rather a "trivial" one, trivial meant in the way of being designed as an intermediary stage that only contains necessary information to transpile to JS. An AST in e.g. clang or other languages would be far more complex as it's more generic and has to cater with all the language specifics (language grammar, type system, etc.). -
@IntrusionCM Having decent type checking is the main selling point of TypeScript - I consider this a bug.
But it can correctly identify the type when i use an intermediate variable. So i guess it can be attributed to the type checker not being mature enough - yet. -
h3rp1d3v5232y@Oktokolo Yes. Something similar. Thanks for the help. Posted a bug report on github
-
Despite it being a MS product, it is open source. Have you considered raising an issue in Github?
typescript is shit.
I have never seen such a stupid bug in other languages.
https://stackblitz.com/edit/...
Apparently, there is no way to do type narrowing in a nested object without using enum
rant