gitaarik / lit-state

Simple shared component state management for LitElement.
https://gitaarik.github.io/lit-state/build/
GNU Lesser General Public License v3.0
139 stars 11 forks source link

Typescript Support is missing #8

Open danazkari opened 3 years ago

danazkari commented 3 years ago

Hello! I love the simplicity of this project and was about to use it, but I was trying to use typescript and it seems like lit-element-state does not support typescript.

Can support be added? Can I help do it?

gitaarik commented 3 years ago

Hi @danazkari, nice that you like the project! I myself am not very familiar with TypeScript. What is necessary to support it? I thought that you could include JavaScript modules in TypeScript without any problems.

danazkari commented 3 years ago

Yup essentially you can... But since it's typed, when you want it needs to know about the types the module has, and since you create a new extendable class out of observeState function, it doesn't know what type of class you're returning.

I can add on my project a file to support the lib but since I have to do it anyways, might as well do it right and contribute to the project 😉

https://github.com/DefinitelyTyped/DefinitelyTyped#how-can-i-contribute

Basically there are two ways, one to add the file to your project or the better way I think, which would be to contribute to DefinitelyTyped which gives people to optionally add the typings only if needed.

danazkari commented 3 years ago

A way to start working on this is to use perhaps scaffold a TS project with open-wc/open-wc-starter-app, import gitaarik/lit-state and then complete the lit-state.d.ts file until it runs properly.

I could avoid using TS altogether but it would really help me to use it on this project I'm working on.

gitaarik commented 3 years ago

Hey @danazkari,

Looks interesting. As I said, I am not familiar with TypeScript, so I would have to learn these concepts before I understand what exactly is needed. I am interested in it, but my time is limited, and I can't promise you that I can fix this any time soon. If you are interested, you can of course maybe make a pull request to fix the issue. In the meantime, I will try to learn more about TypeScript.

danazkari commented 3 years ago

Hey @danazkari,

Looks interesting. As I said, I am not familiar with TypeScript, so I would have to learn these concepts before I understand what exactly is needed. I am interested in it, but my time is limited, and I can't promise you that I can fix this any time soon. If you are interested, you can of course maybe make a pull request to fix the issue. In the meantime, I will try to learn more about TypeScript.

Yeah man it's all good, take ur time, I'm using the ticket as notepad, I wasn't expecting you to work on this actually, but rather I'd like to donate a bit of my time for the project with this 😁

Cheers!

gitaarik commented 3 years ago

Ok cool. I'm excited to see the progress on this :).

marcelpanse commented 2 years ago

@danazkari Did you create the types? Can you share them with me?

danazkari commented 2 years ago

@danazkari Did you create the types? Can you share them with me?

Hey! I'm really sorry mate but I wasn't able to, didn't find the time to do it

christophe-g commented 2 years ago

Early preview of a TS state manager for lit: https://github.com/lit-apps/lit-app/tree/main/packages/state.

Not yet released to npm

gitaarik commented 2 years ago

Nice work!

christophe-g commented 2 years ago

@gitaarik - Yes, thanks ; )

I will slowly transition to this new approach in our apps (for instance accessiblesurveys.com), mostly for better TS support. But I had loved lit-state - thanks a lot for it and all the apprecitated work around it !

gitaarik commented 2 years ago

Thank you, also for your contribution :)