Category: PHP, javascript

A blog on PHP, JavaScript and more Amit Merchant · May 31, 2020 · ⋆ TypeScript Sometimes, all you want to do is a custom type populated with a set of predefined strings which can be used to restrict a variable to only have values from this set of strings. In TypeScript, this can be done by using “string literal types” which allow you to specify the exact value a string must have.

So, for instance, if you want to make a string literal type of the post status, here’s how you can do so.

Follow me on Twitter @amit_merchant Emulate enum-like behavior using string literal types in TypeScript Conditionally validate request fields in Laravel Strictly check for null and undefined values in TypeScript Convert long numbers to short and compact form in JavaScript How to do type-casting in TypeScript
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners