3 ms·
> The any type was a mistake and never should have been included in TypeScript in the first place. Disagree. `any` is important for incremental adoption, not h
by Georgelemental 3y ago
> The any type was a mistake and never should have been included in TypeScript in the first place.
Disagree. `any` is important for incremental adoption, not having it would just make it harder to introduce type-safety to a codebase.
- DarkNova6 3y agoAgreed. The success of TypeScript can only be explained by its direct interoperability with JavaScript. But it is also the bane of its existence.
- cogman10 3y agoThe fact that Typescript was (is?) a superset of Javascript is the reason it won over Dart. You can't be a Javascript superset without any.
- caesil 3y agoCasting and `as unknown as <type>` are just as useful, probably more so because they specify what the type _should_ be.
- ravenstine 3y agoIMO, it's a million times better than accepting something as any, if the latter is possible to avoid. Sadly, every Typescript codebase I've worked with is riddled with `any`, and developers seem skeptical of `as`. That doesn't make sense to me. Throwing your hands up and saying "whatever" is better than declaring what the type should be when Typescript can't infer it otherwise?
- OJFord 3y agoI don't really use JS or TS, so sorry if it should be obvious, but why is that so much better? You just move the (incorrect) assumption from the logic to the type annotation? And you're still not going to get a compile-time error for it, because you're explicitly telling the compiler to make that assumption?
- orwin 3y agoI didn't know about 'as' until right now, because our codebase doesn't use it (we create a lot of weird unions instead),and TS is like 5% of what we do (and we are very small). Thank you, i'll try to see if i can use it when needed, it's a detail but can save me hours imho.
- deleted 3y ago[deleted]
- nkohari 3y agoI think it would have been better if the "unknown" type was available since the start. A lot of developers learned to bail out with "any" when "unknown" is really what they wanted.
- dimitropoulos 3y agoin my heart I feel where the author is coming from (a place of pain and experience).. however.. without an easy adoption path to TypeScript that the any type provided... we'd probably not have TypeScript today. TypeScript works because you can migrate to it incrementally. That's huge for many people.