-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Update sylvester typings to be a cjs module #13627
Conversation
sylvester/index.d.ts to author (@StephaneAlie). Could you review this PR? Checklist
|
As-is this PR would break compilation for people using globals. // No `declare namespace sylvester` wrapper
export class Vector { ... }
export class Matrix { ... }
export class Line { ... }
export class Plane { ... }
// You probably meant "namespace" and not "interface".
export namespace Sylvester {
// `require("sylvester").Sylvester.version` doesn't work for me, but `require("sylvester").Sylvester.approxPrecision` does.
export const precision: number;
export const approxPrecision: number;
}
// Re-export as globals.
import * as s from "sylvester";
declare global {
const Vector: typeof s.Vector;
type Vector = s.Vector;
const Matrix: typeof s.Matrix;
type Matrix = s.Matrix;
const Line: typeof s.Line;
type Line = s.Line;
const Plane: typeof s.Plane;
type Plane = s.Plane;
const Sylvester: typeof s.Sylvester;
// Assuming these are global-only functions
declare function $V(elements: Vector|Array<number>): Vector;
...
declare function $P(anchor: Array<number>|Vector, v1: Array<number>|Vector, v2: Array<number>|Vector): Plane;
} Then have both |
Thanks for the thorough review, I've updated the typings 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving the rest for @StephaneAlie
} | ||
|
||
export namespace Sylvester { | ||
export const version: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you verify that this exists?
@@ -7,819 +7,781 @@ | |||
// Vector and Matrix mathematics modules for JavaScript | |||
// Copyright (c) 2007 James Coglan | |||
|
|||
declare module Sylvester { | |||
interface VectorStatic { | |||
export class Vector { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce indentation (no longer nested)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks a lot cleaner than what I had, thanks for the update!
@@ -1,4 +1,7 @@ | |||
interface IAny { | |||
import { Line, Matrix, Plane, Vector } from 'sylvester'; | |||
import 'sylvester'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you need this?
@connor4312 Please fix the merge conflicts. |
@connor4312 the test file name needs to be changed to |
@connor4312 can you update according to the reviews? Thank you! |
@connor4312: if you can take care of the remaining changes from code review comments we'll be able to merge this PR. Thanks! |
@connor4312 Thanks for your contribution. This PR has unaddressed comments and cannot be merged in at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to merge this code in, please open a new PR that has been merged and rebased with the |
Please fill in this template.
master
branch.tsc
without errors.npm run lint package-name
if atslint.json
is present.If changing an existing definition:
tslint.json
containing{ "extends": "../tslint.json" }
.Sylvester is exported as a CommonJS module and, while it declares some globals, there are requests to remove them and most usage in TypeScript will prefer to use it as a CommonJS module. I did not see a way to provide both global and module exports in a typings file, so I favored converting it to a CommonJS typing and removing the global exports.
I've also updated it to the recommended modern linting rules and best practices.