Skip to content

Avoid having to use esModuleInterop #43

Closed
@danikaze

Description

@danikaze

ES6 modules are supposed to be an object, however this package exports a function by default.
To make it work in TypeScript it requires this option set to true, which means extra code in the build... and would be nice not requiring it.

now:

import clsx from 'clsx';

after:

import { clsx } from 'clsx';

Since this would be a breaking change, I would suggest applying this fix in a way that the old version is also supported -which requires a bit of dirty code- and then apply the clean version in a major version up release :)

// the dirty hack would look like this (types also required)
module.exports.clsx = module.exports;

// so you actually can do both in this version preserving compatibility
import clsx from 'clsx';
import { clsx } from 'clsx';

next version (let's say a major version up) could just export the function like this:

function clsx () {
	var i=0, tmp, x, str='';
	while (i < arguments.length) {
		if (tmp = arguments[i++]) {
			if (x = toVal(tmp)) {
				str && (str += ' ');
				str += x
			}
		}
	}
	return str;
}

module.exports = { clsx };

With this migration we are achieving two things:

  1. Following ES6 standards
  2. Requiring less code when compiling in typescript since esModuleInterop wouldn't be required anymore

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions