Last active
June 25, 2021 12:52
-
-
Save GeordieP/f3190d1f736cd9c195cb136acabf04a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Maybe<T> = T | null; | |
type BlogPost = { | |
title: string; | |
author: string; | |
} | |
type BlogPostResponse = Maybe<{ | |
title?: Maybe<string>, | |
author?: Maybe<string>, | |
}>; | |
const myBlogPost: BlogPostResponse = {/*..*/}; | |
myBlogPost?.title // Maybe<string> | undefined | |
// | |
// Type to unwrap the nested maybes into a concrete type | |
// | |
declare type Definitely<T> = NonNullable<{ [K in keyof T]-?: NonNullable<T[K]> }>; | |
const myBlogPost: Definitely<BlogPostResponse> = {/*..*/}; | |
myBlogPost.title // string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment