Given an array of unique elements, return all possible subsequences.
A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements.
For example:
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
/* _____________ Your Code Here _____________ */
type Subsequence<T extends any[]> = T extends [infer F, ...infer RT]
? Subsequence<RT> | [F, ...Subsequence<RT>]
: []
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Subsequence<[1, 2]>, [] | [1] | [2] | [1, 2]>>,
Expect<Equal<Subsequence<[1, 2, 3]>, [] | [1] | [2] | [1, 2] | [3] | [1, 3] | [2, 3] | [1, 2, 3] >>,
]
标签:elements,_____________,Subsequence,Typescript,Expect,83,type From: https://www.cnblogs.com/Answer1215/p/16844300.html