lukeed / clsx

A tiny (239B) utility for constructing `className` strings conditionally.
MIT License
8.08k stars 141 forks source link

fix(types): fix TypeScript types #58

Closed remcohaszing closed 1 year ago

remcohaszing commented 1 year ago

This only includes the TypeScript type fixes from #57.


CommonJS

tsconfig.json
{
  "compilerOptions": {
    "checkJs": true
  }
}

Before

// ✗ TypeError
require('clsx')('')

// ✔️ Ok
require('clsx').clsx('')

// ✗ Runtime error
require('clsx').default('')

After

// ✔️ Ok
require('clsx')('')

// ✔️ Ok
require('clsx').clsx('')

// ✔️ Runtime and type error
require('clsx').default('')

// tsconfig.json
{
  "compilerOptions": {
    "module": "node16"
  }
}

Before

import clsx from 'clsx'
// ✗ TypeError
clsx('')
// ✗ TypeError
clsx.clsx('')
// ✗ Runtime error
clsx.default('')

// ✗ TypeError
import { clsx } from 'clsx'

After

import clsx from 'clsx'
// ✔️ Ok
clsx('')
// ✔️ Ok
clsx.clsx('')
// ✔️ Runtime error and type error
clsx.default('')

// ✗ TypeError
import { clsx } from 'clsx'

// tsconfig.json
{
  "compilerOptions": {
    "esModuleInterop": true
  }
}

Before

import clsx from 'clsx'
// ✔️ Ok
clsx('')
// ✗ TypeError
clsx.clsx('')
// ✔️ Type error and runtime error
clsx.default('')

// ✔️ Ok
import { clsx } from 'clsx'

After

import clsx from 'clsx'
// ✔️ Ok
clsx('')
// ✔️ Ok
clsx.clsx('')
// ✔️ Type error and runtime error
clsx.default('')

// ✔️ Ok
import { clsx } from 'clsx'
lukeed commented 1 year ago

Superseded by #57. Thank you