{"id":2174119,"date":"2022-05-22T19:34:00","date_gmt":"2022-05-22T17:34:00","guid":{"rendered":"http:\/\/nhub.news\/?p=2174119"},"modified":"2022-05-23T01:32:27","modified_gmt":"2022-05-22T23:32:27","slug":"how-the-typescript-nonnullable-type-works","status":"publish","type":"post","link":"http:\/\/nhub.news\/fr\/2022\/05\/how-the-typescript-nonnullable-type-works\/","title":{"rendered":"How the TypeScript NonNullable Type Works"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>The NonNullable type is a utility type in TypeScript which creates a new type, whilst removing all null or undefined elements.<\/b><br \/>\nJoin the DZone community and get the full member experience. The NonNullable type is a utility type in TypeScript that creates a new type, whilst removing all null or undefined elements. It lets us take existing types, and modify them so they are more suitable in certain situations. Let&rsquo;s look at how it works. This article covers custom types. To learn more about custom types, read my guide about it here. The NonNullable utility type works a lot like other utility types, in that it can take an existing type, and modify it as you see fit. As an example, let&rsquo;s say we have a specific union type that accepts null and undefined as potential options:<br \/> This example works great in one example, but there is another part of our code where we don&rsquo;t want to accept null or undefined. We could create a new type for that, or we could reuse myType, using NonNullable:<br \/> In the above example, noNulls is now of type string| number. Published at DZone with permission of Johnny Simpson, DZone MVB. See the original article here. Opinions expressed by DZone contributors are their own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The NonNullable type is a utility type in TypeScript which creates a new type, whilst removing all null or undefined elements. Join the DZone community and get the full member experience. The NonNullable type is a utility type in TypeScript that creates a new type, whilst removing all null or undefined elements. It lets us [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2174118,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/2174119"}],"collection":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/comments?post=2174119"}],"version-history":[{"count":0,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/2174119\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media\/2174118"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media?parent=2174119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/categories?post=2174119"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/tags?post=2174119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}