main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
918 bytes
|
Rev | Line | |
---|
[d24f17c] | 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 | */
|
---|
| 27 | export declare type NoInfer<A extends any> = [
|
---|
| 28 | A
|
---|
| 29 | ][A extends any ? 0 : never];
|
---|
Note:
See
TracBrowser
for help on using the repository browser.