Is TypeScript Just A Linter?
Is TypeScript just a linter? No, but yes.
![Matt Pocock](/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmatt-pocock.eb3a12a3.jpg&w=96&q=75)
TypeScript 5.0 has made it to Total TypeScript!
It brought a lot of improvements - you can learn all about it in our 5.0 breakdown.
The most exciting feature for Total TypeScript was const type parameters.
It lets you specify a type parameter as const
- meaning that everything that gets passed to that parameter gets inferred as if it were as const
.
const routes = <const TRoutes>( routes: TRoutes ) => { return routes; }; const myRoutes = routes({ user: "/user", createUser: "/user/create", }); Object.values(myRoutes); // ['/user', '/user/create'] // Before 5.0, myRoutes would be inferred as string[]
Before 5.0, you needed to use a hack in TypeScript to get this behaviour - the F.Narrow type helper from ts-toolbelt
. I even taught this in Total TypeScript!
No longer - I've re-recorded 3 exercises in TT's Advanced Patterns workshop to take advantage of const type annotations.
I can't wait to see what you build with them!
Share this article with your friends
Is TypeScript just a linter? No, but yes.
It's a massive ship day. We're launching a free TypeScript book, new course, giveaway, price cut, and sale.
Learn why the order you specify object properties in TypeScript matters and how it can affect type inference in your functions.
Learn how to use corepack
to configure package managers in Node.js projects, ensuring you always use the correct one.
Learn how to strongly type process.env in TypeScript by either augmenting global type or validating it at runtime with t3-env.
Discover when it's appropriate to use TypeScript's any
type despite its risks. Learn about legitimate cases where any
is necessary.