Skip to content

Commit

Permalink
(Typescript) Allow ReadonlyArrays as valid classNames parameters (#307
Browse files Browse the repository at this point in the history
)

* Add `ReadonlyArray<Argument>` to `Argument`

* Add test

* Move to seperate interface for <TS3.7 support
  • Loading branch information
BenGearset authored Apr 27, 2023
1 parent d52250f commit 0251060
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ declare namespace classNames {
type Value = string | number | boolean | undefined | null;
type Mapping = Record<string, unknown>;
interface ArgumentArray extends Array<Argument> {}
type Argument = Value | Mapping | ArgumentArray;
interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {}
type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
}

interface ClassNames {
Expand Down
1 change: 1 addition & 0 deletions tests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classNames('bar', null, undefined, true, false, 1234);
classNames('bar', ['abc', { foo: true }]);
classNames('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
classNames('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
classNames('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }], ['abc', 1234, true, false, undefined, null, { foo: true }] as const);
// $ExpectError
classNames(Symbol());
// $ExpectError
Expand Down

0 comments on commit 0251060

Please sign in to comment.