Skip to content

Commit 7cc7841

Browse files
[FIX]: Coordinate Transformation JSDoc type error in offline mode (#2835)
* Update JSDoc to use CallbackType for return types * Update JSDoc types from function to CallbackType * Apply suggestion from @SleeplessByte --------- Co-authored-by: Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>
1 parent ddc7358 commit 7cc7841

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

exercises/concept/coordinate-transformation/coordinate-transformation.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
// the @ts-check directive. It will give you helpful autocompletion when
55
// implementing this exercise.
66

7+
/**
8+
* @typedef {function (number, number): [number, number]} CallbackType
9+
*/
10+
711
/**
812
* Create a function that returns a function making use of a closure to
913
* perform a repeatable 2d translation of a coordinate pair.
1014
*
1115
* @param {number} dx the translate x component
1216
* @param {number} dy the translate y component
1317
*
14-
* @returns {function} a function which takes an x, y parameter, returns the
18+
* @returns {CallbackType} a function which takes an x, y parameter, returns the
1519
* translated coordinate pair in the form [x, y]
1620
*/
1721
export function translate2d(dx, dy) {
@@ -25,7 +29,7 @@ export function translate2d(dx, dy) {
2529
* @param {number} sx the amount to scale the x component
2630
* @param {number} sy the amount to scale the y component
2731
*
28-
* @returns {function} a function which takes an x, y parameter, returns the
32+
* @returns {CallbackType} a function which takes an x, y parameter, returns the
2933
* scaled coordinate pair in the form [x, y]
3034
*/
3135
export function scale2d(sx, sy) {
@@ -36,10 +40,10 @@ export function scale2d(sx, sy) {
3640
* Create a composition function that returns a function that combines two
3741
* functions to perform a repeatable transformation
3842
*
39-
* @param {function} f the first function to apply
40-
* @param {function} g the second function to apply
43+
* @param {CallbackType} f the first function to apply
44+
* @param {CallbackType} g the second function to apply
4145
*
42-
* @returns {function} a function which takes an x, y parameter, returns the
46+
* @returns {CallbackType} a function which takes an x, y parameter, returns the
4347
* transformed coordinate pair in the form [x, y]
4448
*/
4549
export function composeTransform(f, g) {
@@ -50,11 +54,12 @@ export function composeTransform(f, g) {
5054
* Return a function that memoizes the last result. If the arguments are the same as the last call,
5155
* then memoized result returned.
5256
*
53-
* @param {function} f the transformation function to memoize, assumes takes two arguments 'x' and 'y'
57+
* @param {CallbackType} f the transformation function to memoize, assumes takes two arguments 'x' and 'y'
5458
*
55-
* @returns {function} a function which takes x and y arguments, and will either return the saved result
59+
* @returns {CallbackType} a function which takes x and y arguments, and will either return the saved result
5660
* if the arguments are the same on subsequent calls, or compute a new result if they are different.
5761
*/
5862
export function memoizeTransform(f) {
63+
// To narrow the type of the return variable, add `/** @type {[number, number]} */` above it.
5964
throw new Error('Remove this line and implement the function');
6065
}

0 commit comments

Comments
 (0)