Imagine creating a basic function that doubles its input:
> let f1: (x: number) => number = x => x * 2;
> .type f1
let f1: (x: number) => number
To double the first value, you can use either of these methods:
let f2 = R.pipe( R.take(1), f1 );
let f2 = R.pipe( R.head, f1 );
Both of these examples work when using f2([5,4,3])
, but TypeScript may present challenges:
> let f2 = R.pipe( R.take(1), f1 );
[eval].ts(6,29): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: {}[]) => number'.
Types of parameters 'x' and 'x' are incompatible.
Type '{}[]' is not assignable to type 'number'.
> let f2 = R.pipe( R.head, f1 );
[eval].ts(6,26): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: string) => number'.
Types of parameters 'x' and 'x' are incompatible.
Type 'string' is not assignable to type 'number'.
If you're unsure how to interpret,
Type '{}[]' is not assignable to type 'number'.
and why it mentions string
in the error message,
Type 'string' is not assignable to type 'number'.
(even though there's no mention of string
), you're not alone!