Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

narrow return type of applyToPoint(s) function #67

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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