feat(question): add #59 - Get Optional (#60)

Co-authored-by: Zheeeng <1303154+zheeeng@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2020-08-05 22:02:07 +08:00 committed by GitHub
parent d56905c5e8
commit 2e708a95cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,7 @@
Implement the advanced util type `GetOptional<T>`, which remains all the optional fields
For example
```ts
type I = GetOptional<{ foo: number, bar?: string }> // expected to be { bar?: string }
```

View File

@ -0,0 +1,7 @@
difficulty: hard
title: Get Optional
tags: 'utils, infer'
author:
github: zheeeng
name: Zheeeng

View File

@ -0,0 +1 @@
type GetOptional<T> = any

View File

@ -0,0 +1,6 @@
import { Equal, Expect, ExpectFalse, NotEqual } from '@type-challenges/utils'
type cases = [
Expect<Equal<GetOptional<{ foo: number, bar?: string }>, { bar?: string }>>,
Expect<Equal<GetOptional<{ foo: undefined, bar?: undefined }>, { bar?: undefined }>>,
]