Skip to content

Commit

Permalink
narrow return type of applyToPoint(s) function (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
formatlos authored Apr 13, 2020
1 parent 6f900b6 commit 2eda217
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions transformation-matrix.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
type PointObjectNotation = { x: number; y: number };
type PointArrayNotation = [number, number];

declare module 'transformation-matrix' {
type Matrix = {
a: number;
Expand All @@ -17,7 +20,7 @@ declare module 'transformation-matrix' {
| { type: 'skewY', angle: number }
| { type: 'shear', shx: number, shy: number}

type Point = { x: number; y: number } | [number, number];
type Point = PointObjectNotation | PointArrayNotation;

export { Point, Matrix, MatrixDescriptor };
}
Expand All @@ -26,9 +29,15 @@ declare module 'transformation-matrix/applyToPoint' {
import { Point, Matrix } from 'transformation-matrix';

/** Calculate a point transformed with an affine matrix */
export function applyToPoint(matrix: Matrix, point: Point): Point;
export function applyToPoint<P extends Point>(
matrix: Matrix,
point: P,
): P extends PointObjectNotation ? PointObjectNotation : PointArrayNotation;
/** Calculate an array of points transformed with an affine matrix */
export function applyToPoints(matrix: Matrix, points: Point[]): Point[];
export function applyToPoints<P extends Point>(
matrix: Matrix,
points: P[],
): P extends PointObjectNotation ? PointObjectNotation[] : PointArrayNotation[];
}

declare module 'transformation-matrix/fromString' {
Expand Down

0 comments on commit 2eda217

Please sign in to comment.