From 13102e9baf7becd32b2b3425f2c7624c8fe0087a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:17:45 +0800 Subject: [PATCH] feat(question): add #15260 - Tree path array (#15261) Co-authored-by: Neil Richter <19751938+noook@users.noreply.github.com> --- .../15260-hard-tree-path-array/README.md | 28 +++++++++++++++++++ questions/15260-hard-tree-path-array/info.yml | 6 ++++ .../15260-hard-tree-path-array/template.ts | 1 + .../15260-hard-tree-path-array/test-cases.ts | 20 +++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 questions/15260-hard-tree-path-array/README.md create mode 100644 questions/15260-hard-tree-path-array/info.yml create mode 100644 questions/15260-hard-tree-path-array/template.ts create mode 100644 questions/15260-hard-tree-path-array/test-cases.ts diff --git a/questions/15260-hard-tree-path-array/README.md b/questions/15260-hard-tree-path-array/README.md new file mode 100644 index 00000000..67c9232b --- /dev/null +++ b/questions/15260-hard-tree-path-array/README.md @@ -0,0 +1,28 @@ +Create a type `Path` that represents validates a possible path of a tree under the form of an array. + +Related challenges: +- [Object key path](https://github.com/type-challenges/type-challenges/blob/main/questions/07258-hard-object-key-paths/README.md) + +```ts +declare const example: { + foo: { + bar: { + a: string; + }; + baz: { + b: number + c: number + } + }; +} + +/* Possible solutions: +[] +['foo'] +['foo', 'bar'] +['foo', 'bar', 'a'] +['foo', 'baz'] +['foo', 'baz', 'b'] +['foo', 'baz', 'c'] +*/ +``` diff --git a/questions/15260-hard-tree-path-array/info.yml b/questions/15260-hard-tree-path-array/info.yml new file mode 100644 index 00000000..9045f840 --- /dev/null +++ b/questions/15260-hard-tree-path-array/info.yml @@ -0,0 +1,6 @@ +difficulty: hard +title: Tree path array +author: + github: noook + name: Neil Richter + diff --git a/questions/15260-hard-tree-path-array/template.ts b/questions/15260-hard-tree-path-array/template.ts new file mode 100644 index 00000000..1522d6b6 --- /dev/null +++ b/questions/15260-hard-tree-path-array/template.ts @@ -0,0 +1 @@ +type Path = any diff --git a/questions/15260-hard-tree-path-array/test-cases.ts b/questions/15260-hard-tree-path-array/test-cases.ts new file mode 100644 index 00000000..dd56d0f5 --- /dev/null +++ b/questions/15260-hard-tree-path-array/test-cases.ts @@ -0,0 +1,20 @@ +import type { ExpectTrue,ExpectFalse,ExpectExtends } from '@type-challenges/utils' + +declare const example: { + foo: { + bar: { + a: string; + }; + baz: { + b: number + c: number + } + }; +} + +type cases = [ + ExpectTrue, ['a']>>, + ExpectTrue,['b'] | ['c'] >>, + ExpectTrue, ['bar'] | ['baz'] | ['bar', 'a'] | ['baz', 'b'] | ['baz', 'c']>>, + ExpectFalse, ['z']>>, +]