culori
culori copied to clipboard
Add type definitions
Hi all :-)
This MR is related to https://github.com/Evercoder/culori/issues/128
I'm not the user of this library. I come on call of @ai here https://cultofmartians.com/tasks/culori-types.html
What has been done in the scope of this PR so far:
- [x] types have been added for some exported functions
- [x] it was checked with
npm link
that type defs were exported correctly and can be used in the user project.
The advantage of the approach when declaration files is in the same dir as javascript files is that the types are immediately available to other parts of the code base, for example in tests. Will this advantage be helpful for the maintainers?
May I get feedback at this point?
@Enteleform may I ask you to review this PR?
@akx hi! May I ask you to review this PR?
@ai hi! May I ask you to review this PR?
@akx thank you for review!
@danburzo what else do we need here?
I really need TS support to use your awesome culori
in my project.
@ai @bijela-gora Sorry for the delay, I hope to be able to review this PR soon.
I really need TS support to use your awesome
culori
in my project.
@ai @danburzo I'm here in case you found some inconsistency between documentation and type definitions, or in case some types is not convenient enough.
@ai in the side branch, I removed the prepare
npm script from the list, and now you can install the culori package from GitHub as follows:
pnpm install github:bijela-gora/culori#7fa2b01940ee6c0793455c34872d5cef5d837b9e
@akx FYI :point_up:
@bijela-gora we need to add types for 'culori/fn'
import (after it, I will be able to continue testing types)
@ai do you know how it can be done?
The support of package.json Exports
will be added in TS 4.7
I also found that it is possible to import tree shakeable function using
import { parse } from 'culori/src/index-fn.js';
The support of package.json Exports will be added in TS 4.7
I can install TS 4.7 beta. But it doesn’t work too.
You can try on your own:
- Repo https://github.com/evilmartians/oklch-picker
- File which use
culori
https://github.com/evilmartians/oklch-picker/blob/main/lib/colors.ts
@ai thank you
I will add fn.d.ts
in the project root folder with export * from './src/index-fn';
content and this should solve the issue with 'culori/fn'.
Also I have found that I configure tsconfig in the wrong way, and I need to fix many type definitions. It will take 1 or 2 days.
@bijela-gora ping me when you will be able to run it locally (with new pnpm add
command) and I will test and check types too
@ai ping :-)
Use pnpm remove culori && pnpm add github:bijela-gora/culori#16bcbc35
to update the package in project.
Here is the patch to the oklch-picker with updated types.
@bijela-gora can you send this patch (with package.json
and pnpm-lock.yml
changes) as a PR to save your name in the OKLCH picker history?
Here it is: https://github.com/evilmartians/oklch-picker/pull/35
@danburzo I can prove that types works.
We tested and polished types in https://github.com/evilmartians/oklch-picker/pull/35
@danburzo can we merge it please? TS support is very critical for modern big applications.
I'd also very much like to have this merged :)
If this doesn't get merged, the definitions could be maintained in a separate package too. Of course that's a bit of a chore either way.
@danburzo here is a good statistics why TS support is very important for modern webdev
Almost 80% of modern npm packages have types and developers expect it.
Hi all
I rebased types on latest commit of main branch and added OKLCH & LCH Color Picker to the list of products using Culori.
I'd be very excited to see this working :)
@adiron hi! This working :slightly_smiling_face: Visit the following link to found a way how you can use it: https://github.com/evilmartians/oklch-picker/blob/main/package.json#L21
@danburzo hi! Once you wrote:
(One TypeScripty thing we can do in this repository is maintain a
t.ds
typedef file, if that is helpful.)
I will be grateful if you look at this PR.
Dear @bijela-gora & others in this thread, I have failed to answer when pinged, but I think the situation deserves a status update despite my reluctance before we hit the 1-year mark.
First of all, thank you for what looks to me like an immense amount of work for this PR, and what looks like a successful integration in the excellent evilmartians/oklch-picker ❤️
However, this is a massive PR that turned out to include a lot of files and duplicated code, which I fear is too much of a maintenance burden to take on all at once. (Please bear in mind that, while I am open to the idea of better supporting Typescript users of the library, I am not a TypeScript user myself.)
Therefore, as much as it pains me to say, I will not be able to merge it in this form, at least for the time being. I need to get at least a bit familiar with the technology before I can commit to maintaining it going forward.
I am currently exploring how to generate Declaration files from JavaScript via JSDoc, which I think is the only feasible way forward for types in Culori. I will be posting ideas/progress in #128.
I'm sorry, I know this is a disappointing answer... Once I have a workable solution for generating types, I hope to find a way to integrate the work you've already done here.
@danburzo don’t worry. OKLCH color picker temporary moved to local types https://github.com/evilmartians/oklch-picker/commit/3dd6cbf9c20a7df77cfa4371af2282195ee91ed5
@ai @bijela-gora Given the incredible amount of work already done here, could it make sense to contribute these type definitions to DefinitelyTyped, as @types/culori
?
It would be a nice stopgap solution for the TS users out there until @danburzo can find a long-term solution for maintainable first-party typings.
@danburzo @lordofthelake
I'm going to create a PR to DefinitelyTyped.