UNPKG

918 BTypeScriptView Raw
1/**
2 * Explain to TS which function parameter has priority for generic inference
3 * @param A to de-prioritize
4 * @returns `A`
5 * @example
6 * ```ts
7 * import {F} from 'ts-toolbelt'
8 *
9 * const fn0 = <A extends any>(a0: A, a1: F.NoInfer<A>): A => {
10 * return {} as unknown as A // just for the example
11 * }
12 *
13 * const fn1 = <A extends any>(a0: F.NoInfer<A>, a1: A): A => {
14 * return {} as unknown as A // just for the example
15 * }
16 *
17 * const fn2 = <A extends any>(a0: F.NoInfer<A>, a1: F.NoInfer<A>): A => {
18 * return {} as unknown as A // just for the example
19 * }
20 *
21 * const test0 = fn0('b', 'a') // error: infer priority is `a0`
22 * const test1 = fn1('b', 'a') // error: infer priority is `a1`
23 * const test2 = fn2('b', 'a') // works: infer priority is `a0` | `a1`
24 * ```
25 * @see https://stackoverflow.com/questions/56687668
26 */
27export declare type NoInfer<A extends any> = [
28 A
29][A extends any ? 0 : never];