From 2e708a95cc715fe51a00c60577b56860490b355c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2020 22:02:07 +0800 Subject: [PATCH] feat(question): add #59 - Get Optional (#60) Co-authored-by: Zheeeng <1303154+zheeeng@users.noreply.github.com> --- questions/59-hard-get-optional/README.md | 7 +++++++ questions/59-hard-get-optional/info.yml | 7 +++++++ questions/59-hard-get-optional/template.ts | 1 + questions/59-hard-get-optional/test-cases.ts | 6 ++++++ 4 files changed, 21 insertions(+) create mode 100644 questions/59-hard-get-optional/README.md create mode 100644 questions/59-hard-get-optional/info.yml create mode 100644 questions/59-hard-get-optional/template.ts create mode 100644 questions/59-hard-get-optional/test-cases.ts diff --git a/questions/59-hard-get-optional/README.md b/questions/59-hard-get-optional/README.md new file mode 100644 index 00000000..cf35b64c --- /dev/null +++ b/questions/59-hard-get-optional/README.md @@ -0,0 +1,7 @@ +Implement the advanced util type `GetOptional`, which remains all the optional fields + +For example + +```ts +type I = GetOptional<{ foo: number, bar?: string }> // expected to be { bar?: string } +``` diff --git a/questions/59-hard-get-optional/info.yml b/questions/59-hard-get-optional/info.yml new file mode 100644 index 00000000..49152359 --- /dev/null +++ b/questions/59-hard-get-optional/info.yml @@ -0,0 +1,7 @@ +difficulty: hard +title: Get Optional +tags: 'utils, infer' +author: + github: zheeeng + name: Zheeeng + diff --git a/questions/59-hard-get-optional/template.ts b/questions/59-hard-get-optional/template.ts new file mode 100644 index 00000000..f5699f99 --- /dev/null +++ b/questions/59-hard-get-optional/template.ts @@ -0,0 +1 @@ +type GetOptional = any diff --git a/questions/59-hard-get-optional/test-cases.ts b/questions/59-hard-get-optional/test-cases.ts new file mode 100644 index 00000000..b1ecd1d9 --- /dev/null +++ b/questions/59-hard-get-optional/test-cases.ts @@ -0,0 +1,6 @@ +import { Equal, Expect, ExpectFalse, NotEqual } from '@type-challenges/utils' + +type cases = [ + Expect, { bar?: string }>>, + Expect, { bar?: undefined }>>, +]