3 ms·
> We refer to the supported subset as Modern TypeScript because it represents nearly all TypeScript syntax, except for those TypeScript-specific features that m
by paulddraper 2y ago
> We refer to the supported subset as Modern TypeScript because it represents nearly all TypeScript syntax, except for those TypeScript-specific features that may be considered legacy or discouraged in some way
> These unsupported TypeScript features already have preferred alternatives:
> Prefix-style type assertions (<type>value) should be replaced with as-style type assertions.
Am I out of date? Does someone know something I don't?
- wk_end 2y agoWhat's not explained by the quoted excerpt? Instead of writing, e.g. `const n = <number>someValueThatYouKnowIsANumber;`, you should write `const n = someValueThatYouKnowIsANumber as number;` (well, really, you shouldn't write either, casts are bad. But, yknow.)
- paulddraper 2y agoI mean I have not seen anything to suggest that angle brackets are "legacy or discouraged"
- wk_end 2y agoThey're discouraged because they conflict with JSX. For instance, in the eslint documentation: > Most codebases will want to enforce not using angle-bracket style because it conflicts with JSX syntax, and is confusing when paired with generic syntax. https://typescript-eslint.io/rules/consistent-type-assertions/ https://typescript-eslint.io/rules/consistent-type-assertion...
- paulddraper 2y agoThat's true, but this tool is made for users not using TSX. (Or at least, they can't use this tool with it.)
- animuchan 2y agoThe phrasing sounds a bit odd: surely "most codebases" don't use JSX, so why would they enforce anything JSX-related.
- sureIy 2y agoI don’t think I’ve seen a single codebase using that pattern ever. With React being so popular and TS growing in popularity just about after React, people have settled on `as` assertions instead, whether they use JSX or not.