this post was submitted on 04 Mar 2023
9 points (100.0% liked)
Programmer Humor
32396 readers
502 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I don't really get the point of this. Of course the function will accept the value as a string if you specifically tell it to treat it as such (which wouldn't even be possible without casting it to
unknown
first)?I guess the point is, it's not strongly typed during runtime. In other strongly typed languages, that cast would fail, since the underlying memory layout of some random class does not fit to that of a string.
But yeah, as soon as you break out
as
, you're telling the type system to fuck off. So, while it does look freaky to me, too, it doesn't dispell that TypeScript is strongly typed...Yeah, I do agree that it's a bit weird with TS. It's fully understandable though, since it just transpiles to JS, which doesn't have any type information during runtime. I think as far as webdev goes though, TS makes it at least somewhat bearable.
Sorry for the downvote btw - that wasn't me!