Skip to content

Commit 3ec8e9f

Browse files
authoredJul 15, 2023
break: include "exports" map w/ "types" conditions (#57)
The non-standard `package.json` field `module` was used. This pointed to a faux ESM file (Uses ESM syntax, but has a `.js` file extension in a package which doesn’t specify `"type": "module"`. ESM support was fixed by using the `.mjs` file extension for the ESM export and defining a proper `exports` field in `package.json. The types reflected a package that has the `module.exports.default` field. This was incorrect. The CommonJS types have now been fixed to use `export =`, which is the correct way to type modules that use `module.exports` assignments. Additional types were added for ESM support.
1 parent 4a4eadd commit 3ec8e9f

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed
 

‎clsx.d.mts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
2+
export type ClassDictionary = Record<string, any>;
3+
export type ClassArray = ClassValue[];
4+
5+
export function clsx(...inputs: ClassValue[]): string;
6+
export default clsx;

‎clsx.d.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
2-
export type ClassDictionary = Record<string, any>;
3-
export type ClassArray = ClassValue[];
1+
declare namespace clsx {
2+
type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
3+
type ClassDictionary = Record<string, any>;
4+
type ClassArray = ClassValue[];
5+
function clsx(...inputs: ClassValue[]): string;
6+
}
47

5-
export declare function clsx(...inputs: ClassValue[]): string;
6-
export default clsx;
8+
declare function clsx(...inputs: clsx.ClassValue[]): string;
9+
10+
export = clsx;

‎package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
"version": "1.2.1",
44
"repository": "lukeed/clsx",
55
"description": "A tiny (228B) utility for constructing className strings conditionally.",
6-
"module": "dist/clsx.m.js",
6+
"module": "dist/clsx.mjs",
77
"unpkg": "dist/clsx.min.js",
88
"main": "dist/clsx.js",
9+
"exports": {
10+
"import": {
11+
"types": "./clsx.d.mts",
12+
"default": "./dist/clsx.mjs"
13+
},
14+
"default": {
15+
"types": "./clsx.d.ts",
16+
"default": "./dist/clsx.js"
17+
}
18+
},
919
"types": "clsx.d.ts",
1020
"license": "MIT",
1121
"author": {

0 commit comments

Comments
 (0)
Please sign in to comment.