ocket8888 commented on code in PR #7414:
URL: https://github.com/apache/trafficcontrol/pull/7414#discussion_r1142326980
##########
traffic_portal/app/src/common/modules/form/deliveryService/FormDeliveryServiceController.js:
##########
@@ -113,6 +113,21 @@ var FormDeliveryServiceController =
function(deliveryService, dsCurrent, origin,
deliveryService.tlsVersions?.splice(index+1, 0, "");
};
+ /** Compare Arrays
+ * @param {array} a
+ * @param {array} b
Review Comment:
`array` is not a type. To declare an array of homogeneous element type `T`,
the syntax is `Array<T>` or `T[]`. The types that can be compared using strict
inequality are `number`, `bigint`, `string`, `boolean`, `undefined`, and `null`
- but since `null` and `undefined` typed values are always totally equal I
wouldn't expect this to ever be used on such arrays, because that's kind of
pointless. `a` and `b` must be of the same homogeneous element type to use this
function, so you probably want to template the type for re-use using [the
`@template` JSDoc
tag](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template).
Since the types have to be homogeneous, the type's constraint should be
`number[] | bigint[] | boolean[] | string[]` (**not** `Array<number | bigint |
boolean | string>`, which might seem like the same thing but it isn't).
But that's only if you want the JSDoc to be correctly typed. It doesn't
actually matter, because since `$scope` has the `any` type, no comment you can
put here actually "sticks" to the function. You could, on the next line, call
it like `$scope.arrayCompare(null, {test: "quest"})` and no type-checker would
say it's wrong. If you want it to stick to the function, you need to define the
function separately and *then* assign it as a method of `$scope`, e.g.
```javascript
/**
* Compares two arrays.
*
* @template T extends number[] | boolean[] | bigint[] | string[]
*
* @param {T} a
* @param {T} b
* @returns `false` if the arrays are equal, `true` otherwise.
*/
function arrayCompare(a, b) {
// ...
return false;
}
$scope.arrayCompare = arrayCompare;
```
But, finally, JSDoc comments aren't required in TPv1. They are very nice to
have, though. If you want to add the typings, I'd ask that they be correct and
actually bound to the function, but if you don't want to do them you don't have
to.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]