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']>>, +]