Skip to content

Commit 08921f0

Browse files
TypeScript: Migrate is-shallow-equal package to TypeScript (#70407)
* refactor: migrate is-shallow-equal package from js to ts for type safety * docs: remove jsDoc types as used ts
1 parent 76223e7 commit 08921f0

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

packages/is-shallow-equal/src/arrays.js renamed to packages/is-shallow-equal/src/arrays.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/**
22
* Returns true if the two arrays are shallow equal, or false otherwise.
33
*
4-
* @param {any[]} a First array to compare.
5-
* @param {any[]} b Second array to compare.
4+
* @param a First array to compare.
5+
* @param b Second array to compare.
66
*
7-
* @return {boolean} Whether the two arrays are shallow equal.
7+
* @return Whether the two arrays are shallow equal.
88
*/
9-
export default function isShallowEqualArrays( a, b ) {
9+
export default function isShallowEqualArrays(
10+
a: unknown[],
11+
b: unknown[]
12+
): boolean {
1013
if ( a === b ) {
1114
return true;
1215
}

packages/is-shallow-equal/src/index.js renamed to packages/is-shallow-equal/src/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import isShallowEqualArrays from './arrays';
77
export { default as isShallowEqualObjects } from './objects';
88
export { default as isShallowEqualArrays } from './arrays';
99

10-
/**
11-
* @typedef {Record<string, any>} ComparableObject
12-
*/
10+
export type ComparableObject = Record< string, any >;
1311

1412
/**
1513
* Returns true if the two arrays or objects are shallow equal, or false
1614
* otherwise. Also handles primitive values, just in case.
1715
*
18-
* @param {unknown} a First object or array to compare.
19-
* @param {unknown} b Second object or array to compare.
16+
* @param a First object or array to compare.
17+
* @param b Second object or array to compare.
2018
*
21-
* @return {boolean} Whether the two values are shallow equal.
19+
* @return Whether the two values are shallow equal.
2220
*/
23-
export default function isShallowEqual( a, b ) {
21+
export default function isShallowEqual( a: unknown, b: unknown ): boolean {
2422
if ( a && b ) {
2523
if ( a.constructor === Object && b.constructor === Object ) {
2624
return isShallowEqualObjects( a, b );

packages/is-shallow-equal/src/objects.js renamed to packages/is-shallow-equal/src/objects.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import type { ComparableObject } from '.';
5+
16
/**
27
* Returns true if the two objects are shallow equal, or false otherwise.
38
*
4-
* @param {import('.').ComparableObject} a First object to compare.
5-
* @param {import('.').ComparableObject} b Second object to compare.
9+
* @param a First object to compare.
10+
* @param b Second object to compare.
611
*
7-
* @return {boolean} Whether the two objects are shallow equal.
12+
* @return Whether the two objects are shallow equal.
813
*/
9-
export default function isShallowEqualObjects( a, b ) {
14+
export default function isShallowEqualObjects(
15+
a: ComparableObject,
16+
b: ComparableObject
17+
): boolean {
1018
if ( a === b ) {
1119
return true;
1220
}

0 commit comments

Comments
 (0)