lukeed/clsxPublic

A tiny (239B) utility for constructing `className` strings conditionally.

Added a typescript defs file #5

Mergedmaraisrmerged 4 commits intomasterfromrefs/pull/5/head
  1. MA

    Not sure we need all the fancy things from that @types/classnames repo - but here is something nice and tight.

    If you're not too keen; happy to amend this with a simple copy-paste from their one, and rename somethings.

    resolves #3

  2. maraisrreferenced this in feat: added a typescript defs file #47 years ago on GitHub

  3. LU

    @kentcdodds looks good to me, how about to you?

  4. kentcdoddsmentioned7 years ago on GitHub

  5. kentcdoddssubscribed7 years ago on GitHub

  6. TR
    Hidden as resolved.
  7. TR

    No review summary.

  8. KE
    Hidden as resolved.
  9. KE

    No review summary.

  10. KE
    Hidden as resolved.
  11. KE
    Hidden as resolved.
  12. KE
    kentcdoddsChanges requested

    Once we fix the exports this'll be ready.

    Thanks for considering including this @lukeed!

    We'll also need to add `index.d.ts` to the `package.json` `files` property.

  13. LU

    Aye, I'll take care of properly distributing the types to npm โ€“ that's about all I can contribute here.

    As per Twitter thread, I can't really weigh in on the right/wrong/better ways for typings, so once you all come to an agreement I'll merge.

    ---

    I will say that multiple of my repos have been PR'd with `export = lib`. @marvinhagemeister shared [this link](https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require) with me about it.

  14. marvinhagemeistermentioned7 years ago on GitHub

  15. marvinhagemeistersubscribed7 years ago on GitHub

  16. KE

    I'm pretty new to TS, but from what I understand `export =` is an old way to do things that pre-dates the ESModules specification. In my own version of these definitions, I'm using `export default` and that's working well :+1: (plus `export {ClassArray, ClassDictionary, ClassValue}`)

  17. LU

    Ah, then I suppose the above was specific to `kleur` since it's Node/CommonJS only & can be required as default or partially.

  18. LU

    Is this final form?

    ```ts export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean;

    export interface ClassDictionary { [id: string]: any; }

    export interface ClassArray extends Array<ClassValue> { }

    declare const clsx: (...classes: ClassValue[]) => string;

    export default clsx; ```

  19. KE

    Yep, I think that'll do it!

  20. MA

    yup, the `export = foo` way is only needed when the library doesn't use proper exports and uses plain CommonJS style exports (`module.exports = foo`) instead. The only exception is when the special `__esModule` property is defined on `exports`:

    ```js // Note: exports === module.exports Object.defineProperty(exports, "__esModule", { value: true }); ```

    In the case for `clsx` the proper way to do it is via a `export default` expression as already suggested ๐Ÿ‘

  21. KE

    Thanks for the help @marvinhagemeister!

  22. marvinhagemeistermentioned7 years ago on GitHub

  23. marvinhagemeistersubscribed7 years ago on GitHub

  24. LU

    Thank you @marvinhagemeister, makes sense~!

    And thank you all, especially @maraisr, for the types. Since they are so simple & small, I'll just add them here after all. Patch incoming~

  25. maraisrmentioned7 years ago on GitHub

  26. maraisrsubscribed7 years ago on GitHub

  27. marvinhagemeistermentioned7 years ago on GitHub

  28. marvinhagemeistersubscribed7 years ago on GitHub

  29. lukeedmerged 08d028fd29217 years ago on GitHub

  30. lukeedclosed7 years ago on GitHub

  31. KE
  32. LU

    Released in `1.0.1` ๐Ÿ™Œ