- 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
maraisrreferenced this in feat: added a typescript defs file #47 years ago on GitHub
- LU
@kentcdodds looks good to me, how about to you?
kentcdoddsmentioned7 years ago on GitHub
kentcdoddssubscribed7 years ago on GitHub
- TRHidden as resolved.
- TR
No review summary.
- KEHidden as resolved.
- KE
No review summary.
- KEHidden as resolved.
- KEHidden as resolved.
- KE
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.
- 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.
marvinhagemeistersubscribed7 years ago on GitHub
- 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}`)
- LU
Ah, then I suppose the above was specific to `kleur` since it's Node/CommonJS only & can be required as default or partially.
- 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; ```
- KE
Yep, I think that'll do it!
- 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 ๐
- KE
Thanks for the help @marvinhagemeister!
marvinhagemeistersubscribed7 years ago on GitHub
- 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~
maraisrmentioned7 years ago on GitHub
maraisrsubscribed7 years ago on GitHub
marvinhagemeistersubscribed7 years ago on GitHub
lukeedmerged 08d028fd29217 years ago on GitHub
- KE
๐
- LU
Released in `1.0.1` ๐