Open
Description
Same errors, locations, and messages as TS5.8
yet another little difference
(types are mostly copied from remeda
)
type IterableContainer<T = unknown> = ReadonlyArray<T> | readonly [];
type Mapped<T extends IterableContainer, K> = {
-readonly [P in keyof T]: K;
};
declare function pipe<A, B>(value: A, op1: (input: A) => B): B;
declare function map<T extends IterableContainer, U>(
callbackfn: (value: T[number], index: number, data: T) => U,
): (data: T) => Mapped<T, U>;
type Point = { x?: number } & { y?: number };
export function update(modify?: (point: Point) => Point) {
return pipe(
[{ x: 0 }],
modify
? map(modify)
: map((point) => point),
);
}
error TS2345: Argument of type '((data: { x: number; }[]) => { x: number; }[]) | ((data: { x: number; }[]) => Point[])' is not assignable to parameter of type '(input: { x: number; }[]) => { x: number; }[]'.
Type '(data: { x: number; }[]) => Point[]' is not assignable to type '(input: { x: number; }[]) => { x: number; }[]'.
Type 'Point[]' is not assignable to type '{ x: number; }[]'.
Type 'Point' is not assignable to type '{ x: number; }'.
Types of property 'x' are incompatible.
Type 'number | undefined' is not assignable to type 'number'.
Type 'undefined' is not assignable to type 'number'.
16 modify
~~~~~~
17 ? map(modify)
~~~~~~~~~~~~~~~~~~~
18 : map((point) => point),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TS 5.8 is OK with that: playground
If we merge { x?: number } & { y?: number }
as { x?: number; y?: number }
the error disappears (but in my core I merge different types).