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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners