Intersect method type error in typescript.
The issues section is used only for bug reports. Please use the Discussions section to ask questions and share ideas and suggestions.
Describe the bug I want to calculate intersection between a line and a plane using intersect method. But I got type error in VS Code because this method is defined with 4 non-optional parameters In the official document, the last parameter can be undefined. We should fix the last parameter of the method to optional.
To Reproduce
- Craete React App with typescript template (React 17)
- Run
yarn add mathjsto install math.js - Test below code.
const p1 = [-1, 1, 0];
const p2 = [1, 1, 0];
const plane = [1, 0, 0, 0];
intersect(p1, p2, plane); // type error!
I used type assertion like below code, and intersect method worked well. But In my opinion, we need to fix type definition for intersect method.
export const intersectLineAndPlane = intersect as (
w: MathCollection,
x: MathCollection,
y: MathCollection,
z?: MathCollection,
) => MathArray[];
I misunderstand it.
OMG, It is not work to use intersect(a, b, c, undefined);
Uncaught TypeError: Unexpected type of argument in function intersect (expected: Array or Matrix, actual: identifier | undefined, index: 3)
at _loop (typed-function.js:956:1)
at Function.createError (typed-function.js:974:1)
at typed.onMismatch (typed.js:398:1)
at generic (typed-function.js:1861:1)
at intersect (typed-function.js:1891:1)
So We should to fix the type.
- Intersect method works well using type assertion.
export const intersectLineAndPlane = intersect as (
w: MathCollection,
x: MathCollection,
y: MathCollection,
z?: MathCollection,
) => MathArray[];
- Intersect method not works with undefined last parameter.
intersect(a, b, c, undefined)
The fixed definitions are now published in v11.6.0.