The const assertion is when you're creating an object in JavaScript. You can tack on as const onto the end of it and what that will do is It will do extreme type narrowing meaning that the The type of an object if you don't specify the type inIn the case of mine was title string descriptionstring number of episodes number right so string string number. What as const will do is it will narrow it down from not just any string but literally the string of syntax FM the description goes from a broad string any string to the string of Whatever description we put in there. That's really cool becauseyou have now just created a type in TypeScript From the actual data that has been
In this Hasty Treat, Scott and Wes talk about Satisfies and as const.
Show Notes
export const currencies = { USD: 'US Dollars', CAD: 'Canadian Dollar', EUR: 'Euro', } as const; export type Currency = typeof currencies; export type CurrencyCode = keyof Currency;
Tweet us your tasty treats