Skip to content

Commit

Permalink
Restore ability to pass TypeScript interface (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops committed Dec 27, 2023
1 parent 930c748 commit ea8e839
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -10,7 +10,7 @@

declare namespace classNames {
type Value = string | number | boolean | undefined | null;
type Mapping = Record<string, unknown>;
type Mapping = Record<string, any>;
interface ArgumentArray extends Array<Argument> {}
interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {}
type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
Expand Down
16 changes: 14 additions & 2 deletions tests/bind.test-d.ts
@@ -1,6 +1,18 @@
import {expectError} from 'tsd';
import bind from '../bind';

type Foo = {
bar: boolean;
};

const foo: Foo = { bar: true };

interface IFoo {
bar: boolean;
}

const ifoo: IFoo = { bar: true };

// bind
bind.default.bind({foo: 'bar'});
const bound = bind.bind({foo: 'bar'});
Expand All @@ -22,6 +34,6 @@ bound('bar', null, undefined, true, false, 1234);
bound('bar', ['abc', { foo: true }]);
bound('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
bound('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
bound(foo);
bound(ifoo);
expectError(bound(Symbol()));
expectError(bound([Symbol()]));
expectError(bound([[Symbol()]]));
16 changes: 14 additions & 2 deletions tests/dedupe.test-d.ts
@@ -1,6 +1,18 @@
import {expectError} from 'tsd';
import dedupe from '../dedupe';

type Foo = {
bar: boolean;
};

const foo: Foo = { bar: true };

interface IFoo {
bar: boolean;
}

const ifoo: IFoo = { bar: true };

// dedupe
dedupe.default('foo');
dedupe('foo');
Expand All @@ -19,6 +31,6 @@ dedupe('bar', null, undefined, true, false, 1234);
dedupe('bar', ['abc', { foo: true }]);
dedupe('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
dedupe('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
dedupe(foo);
dedupe(ifoo);
expectError(dedupe(Symbol()));
expectError(dedupe([Symbol()]));
expectError(dedupe([[Symbol()]]));
18 changes: 14 additions & 4 deletions tests/index.test-d.ts
@@ -1,6 +1,18 @@
import {expectError} from 'tsd';
import classNames from '..';

type Foo = {
bar: boolean;
};

const foo: Foo = { bar: true };

interface IFoo {
bar: boolean;
}

const ifoo: IFoo = { bar: true };

// default
classNames.default('foo');
classNames('foo');
Expand All @@ -20,11 +32,9 @@ 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);

classNames(foo);
classNames(ifoo);
expectError(classNames(Symbol()));
expectError(classNames([Symbol()]));
expectError(classNames([[Symbol()]]));

// should match tests/index.js
classNames('c', ['a', 'b']);
classNames('', 'b', {}, '');
Expand Down

0 comments on commit ea8e839

Please sign in to comment.