chore(utils): migrate CSS dimensions utility to TypeScript

Added type annotations to the CSS dimensions utility (cssDimensions) and
to its testing module. Both have been updated to .ts.
This commit is contained in:
jakob.scheid committed 2026-10-25 02:37:18 +01:00
1 parent 0140e5669e
commit ffee1d0569
2 files changed
+15 -3

No files matched your search

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { ensureUnit } from '../cssDimensions';
import { ensureUnit, type RawDimension } from '../cssDimensions';
import { describe, expect, test } from 'vitest';
describe('cssDimensions', () => {
@@ -129,7 +129,13 @@ describe('cssDimensions', () => {
},
])(
'ensureUnit returns $expected with input $dimension',
({ dimension, expected }) => {
({
dimension,
expected,
}: {
dimension: RawDimension;
expected: string;
}) => {
expect(ensureUnit(dimension)).toBe(expected);
},
);
@@ -14,7 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
export const ensureUnit = function ensureUnit(d) {
/*
* null and undefined because they are intended to represent empty input
* values
*/
export type RawDimension = null | number | string | undefined;
export const ensureUnit = function ensureUnit(d: RawDimension): string {
if (!d) d = 0;
// ensure that it is a string