culori icon indicating copy to clipboard operation
culori copied to clipboard

Add type definitions

Open bijela-gora opened this issue 2 years ago • 24 comments

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?

bijela-gora avatar Apr 05 '22 20:04 bijela-gora

@Enteleform may I ask you to review this PR?

bijela-gora avatar Apr 11 '22 21:04 bijela-gora

@akx hi! May I ask you to review this PR?

bijela-gora avatar Apr 11 '22 21:04 bijela-gora

@ai hi! May I ask you to review this PR?

bijela-gora avatar Apr 11 '22 21:04 bijela-gora

@akx thank you for review!

bijela-gora avatar Apr 14 '22 18:04 bijela-gora

@danburzo what else do we need here?

I really need TS support to use your awesome culori in my project.

ai avatar Apr 24 '22 22:04 ai

@ai @bijela-gora Sorry for the delay, I hope to be able to review this PR soon.

danburzo avatar Apr 28 '22 12:04 danburzo

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.

bijela-gora avatar Apr 28 '22 22:04 bijela-gora

@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

bijela-gora avatar May 07 '22 19:05 bijela-gora

@akx FYI :point_up:

bijela-gora avatar May 07 '22 19:05 bijela-gora

@bijela-gora we need to add types for 'culori/fn' import (after it, I will be able to continue testing types)

ai avatar May 09 '22 21:05 ai

@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';

bijela-gora avatar May 10 '22 18:05 bijela-gora

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:

  1. Repo https://github.com/evilmartians/oklch-picker
  2. File which use culori https://github.com/evilmartians/oklch-picker/blob/main/lib/colors.ts

ai avatar May 10 '22 19:05 ai

@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 avatar May 10 '22 19:05 bijela-gora

@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 avatar May 10 '22 20:05 ai

@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.

updated-types.zip

bijela-gora avatar May 13 '22 12:05 bijela-gora

@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?

ai avatar May 13 '22 12:05 ai

Here it is: https://github.com/evilmartians/oklch-picker/pull/35

bijela-gora avatar May 13 '22 12:05 bijela-gora

@danburzo I can prove that types works.

We tested and polished types in https://github.com/evilmartians/oklch-picker/pull/35

ai avatar May 17 '22 10:05 ai

@danburzo can we merge it please? TS support is very critical for modern big applications.

ai avatar Jun 25 '22 11:06 ai

I'd also very much like to have this merged :)

TimJentzsch avatar Jul 21 '22 09:07 TimJentzsch

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.

akx avatar Jul 21 '22 10:07 akx

@danburzo here is a good statistics why TS support is very important for modern webdev

FXAFxaAUIAI2s2s

Almost 80% of modern npm packages have types and developers expect it.

ai avatar Aug 05 '22 21:08 ai

Hi all

I rebased types on latest commit of main branch and added OKLCH & LCH Color Picker to the list of products using Culori.

bijela-gora avatar Aug 12 '22 10:08 bijela-gora

I'd be very excited to see this working :)

adiron avatar Aug 20 '22 15:08 adiron

@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

bijela-gora avatar Jan 08 '23 19:01 bijela-gora

@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.

bijela-gora avatar Jan 08 '23 19:01 bijela-gora

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 avatar Feb 17 '23 21:02 danburzo

@danburzo don’t worry. OKLCH color picker temporary moved to local types https://github.com/evilmartians/oklch-picker/commit/3dd6cbf9c20a7df77cfa4371af2282195ee91ed5

ai avatar Feb 20 '23 11:02 ai

@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.

lordofthelake avatar Mar 05 '23 22:03 lordofthelake

@danburzo @lordofthelake

I'm going to create a PR to DefinitelyTyped.

bijela-gora avatar Mar 09 '23 13:03 bijela-gora