Skip to content

Commit

Permalink
Fix TypeScript types (#276)
Browse files Browse the repository at this point in the history
The package uses commonjs, but it’s typed as if it contains faux ESM.
This was problematic for people using `require` or the new `node16`
module resolution.
  • Loading branch information
remcohaszing authored Sep 12, 2022
1 parent 8cac391 commit 2a42583
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
12 changes: 8 additions & 4 deletions bind.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export * from '.';
import { ArgumentArray } from '.';
import { ArgumentArray } from './index.js';

export type Binding = Record<string, string>;
export default function classNames(this: Binding | undefined, ...args: ArgumentArray): string;
declare namespace classNames {
type Binding = Record<string, string>;
}

declare function classNames(this: classNames.Binding | undefined, ...args: ArgumentArray): string;

export = classNames;
4 changes: 2 additions & 2 deletions dedupe.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from '.';
export { default } from '.';
import classNames = require('./index.js');
export = classNames;
15 changes: 9 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
// Sean Kelley <https://github.com/seansfkelley>
// Michal Adamczyk <https://github.com/mradamczyk>
// Marvin Hagemeister <https://github.com/marvinhagemeister>
// TypeScript Version: 3.0

export type Value = string | number | boolean | undefined | null;
export type Mapping = Record<string, unknown>;
export interface ArgumentArray extends Array<Argument> {}
export type Argument = Value | Mapping | ArgumentArray;
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;
}

/**
* A simple JavaScript utility for conditionally joining classNames together.
*/
export default function classNames(...args: ArgumentArray): string;
declare function classNames(...args: classNames.ArgumentArray): string;

export = classNames;
6 changes: 3 additions & 3 deletions tests/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import dedupe from 'classnames/dedupe';
import bind from 'classnames/bind';
import classNames = require('classnames');
import dedupe = require('classnames/dedupe');
import bind = require('classnames/bind');

// default
classNames('foo');
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "es2015",
"module": "commonjs",
"lib": ["es2015"],
"moduleResolution": "node",
"strict": true,
Expand Down

0 comments on commit 2a42583

Please sign in to comment.