mirror of
https://github.com/type-challenges/type-challenges.git
synced 2025-12-08 19:06:13 +00:00
Co-authored-by: Neil Richter <19751938+noook@users.noreply.github.com>
This commit is contained in:
parent
a57e8323c2
commit
13102e9baf
28
questions/15260-hard-tree-path-array/README.md
Normal file
28
questions/15260-hard-tree-path-array/README.md
Normal file
@ -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']
|
||||
*/
|
||||
```
|
||||
6
questions/15260-hard-tree-path-array/info.yml
Normal file
6
questions/15260-hard-tree-path-array/info.yml
Normal file
@ -0,0 +1,6 @@
|
||||
difficulty: hard
|
||||
title: Tree path array
|
||||
author:
|
||||
github: noook
|
||||
name: Neil Richter
|
||||
|
||||
1
questions/15260-hard-tree-path-array/template.ts
Normal file
1
questions/15260-hard-tree-path-array/template.ts
Normal file
@ -0,0 +1 @@
|
||||
type Path<T> = any
|
||||
20
questions/15260-hard-tree-path-array/test-cases.ts
Normal file
20
questions/15260-hard-tree-path-array/test-cases.ts
Normal file
@ -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<ExpectExtends<Path<typeof example['foo']['bar']>, ['a']>>,
|
||||
ExpectTrue<ExpectExtends<Path<typeof example['foo']['baz']>,['b'] | ['c'] >>,
|
||||
ExpectTrue<ExpectExtends<Path<typeof example['foo']>, ['bar'] | ['baz'] | ['bar', 'a'] | ['baz', 'b'] | ['baz', 'c']>>,
|
||||
ExpectFalse<ExpectExtends<Path<typeof example['foo']['bar']>, ['z']>>,
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user