diff --git a/src/utils/__tests__/cssDimensions.test.js b/src/utils/__tests__/cssDimensions.test.ts similarity index 96% rename from src/utils/__tests__/cssDimensions.test.js rename to src/utils/__tests__/cssDimensions.test.ts index 2deb302..fa4ac56 100644 --- a/src/utils/__tests__/cssDimensions.test.js +++ b/src/utils/__tests__/cssDimensions.test.ts @@ -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); }, ); diff --git a/src/utils/cssDimensions.js b/src/utils/cssDimensions.ts similarity index 77% rename from src/utils/cssDimensions.js rename to src/utils/cssDimensions.ts index c0e35d7..2010aab 100644 --- a/src/utils/cssDimensions.js +++ b/src/utils/cssDimensions.ts @@ -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