Comments (9)
The library itself, quite possibly, does not need a TS. But when I use it in projects written on the TS, I get a lack of types. All that any hook returns is type "any". This is inconvenient, and sometimes impossible (with strict checks enabled, such as --noImplicitAny
).
I see several options:
-
Writing typings to me myself and copy them from project to project (other users will have to do the same). In this case, if the version is updated, everything may be broken.
-
Writing typings for the DefinitelyTyped repository. Then anyone can download them manually. But at the same time, in this case of an update, everything may also be broken.
-
Writing typings in your repository (
d.ts
files near JS files). In this case, the typings will be available immediately after installing this package, without additional actions and individual packages from DefinitelyTyped. There still remains the option that the library will be updated, and the typings will not. -
And the best option is to rewrite the project on the TS and get the same javascript at the output, but with automatically generated
d.ts
with typings.
Maybe I’m wrong somewhere, I’m not an expert in the development of packages on the TS, but I write my projects on the TS and so far have to use the first option.
from react-timer-hook.
I understand you, thanks.
I’ll prepare typings as soon as I can.
from react-timer-hook.
TypeScript type definition file is available from v1.1.9, Thanks @dartess for your effort on this
from react-timer-hook.
Hi, honestly don't see the need for it in a small library, the library is composed of 3 very small hooks, i think keeping it simple as is without Typescript or Flow is better for now
from react-timer-hook.
I am not an expert in Typescript didn't work much with it till now, but feel a bit weird about the fact that working with Typescript is forcing you or causing issues for you to work with another external library, also forcing you to have libraries to be written in TS, the question now, for the same reason why we don't rewrite the library with Flow ? for those using Flow ?
Based on my understanding you should be able to use any external library that is not written in Typescript or Flow inside any project written in anyone of them. maybe i am missing something
I will also start learning more about Typescript to try to understand how far this can cause issues.
from react-timer-hook.
why we don't rewrite the library with Flow
I have no experience with flow. It seems that I saw some libraries that had typings for both TS and flow at the same time. But now I have no idea where I saw it.
However, I can definitely say that TS is trite more popular than flow among developers for 2018.
Based on my understanding you should be able to use any external library that is not written in Typescript or Flow inside any project written in anyone of them.
We can use them, but without types we cannot use them fully. If the authors of library cannot or do not want to use TS (option 4) or distribute the library with typings (option 3), the community itself writes typings for everyone (option 2) or for themselves (option 1).
from react-timer-hook.
Hi @dartess sorry for my late response about this issue, as i read a bit more about TypeScript
still didn't use it in any of my current projects, but i had a glance of where you are right now if you use strict mode and got better understanding of the options you previously mentioned.
So coming back to these options, we all agree that option 1
and 2
are not ideal.
I am open to option 3
where we add type definition files and we distribute it with the library, i prefer this option because we still keep the source code of the library written in vanilla javascript, this way the library can be used in any project not only Typescript projects, also this will give us the option to add flow support later using the same way in flow "library definition" files
Also don't worry about type definition file not being updated with new versions i will make sure to update it with any library update.
Let me know if you can help in adding type definition file for TypeScript, otherwise i will try to add it soon, also will try to add one for flow at some point
Thanks
from react-timer-hook.
this way the library can be used in any project not only Typescript projects
The library can be used in any project in any case. TS compiles to vanilla JS+d.ts with typings. Developers of javascript projects will not see any changes in any case.
also this will give us the option to add flow support later using the same way in flow "library definition" files
-
Flow is so rarely used that it was removed from the survey state of javascript 2019 (https://2019.stateofjs.com/javascript-flavors/). The results of the survey for the previous year I have already sent above.
-
Even if we will want to add files for flow, I can try using https://github.com/joarwilk/flowgen for automatic generation files for flow and if the result is satisfactory I would suggest adopting the fourth option.
Based on the information above, are you sure that option 3 is the best?
Let me know if you can help in adding type definition file for TypeScript, otherwise i will try to add it soon, also will try to add one for flow at some point
I can help with options 3 or 4 until January 9th.
from react-timer-hook.
Yes TS will compile to vanilla JS but this means, either react-timer-hook
will handle that compiling configuration, or the other library that use the code will need to handle that and what i wanted to do is an out of the box solution.
I like solution 3 because it requires adding a single file for TypeScript or Flow without adding extra compiling configuration to the library, this does make the library simple, generic and future proof
From your perspective Flow is not used enough or does not require the effort to support it, but i believe that still many projects are using Flow for typing i am currently working on some of them and i know that other people are using them as well, being removed from a survey is not enough to not support it at all (in my opinion), even if TypeScript is used more than Flow
Finally as i tried to explain i am trying to find the best solution and avoid attaching a specific technology to the library, also i am not a big fan of languages that is superset of javascript like (Just my own opinion), Typing is nice to have and that is why i like the idea of option 3 where we have a separate d.ts
file without writing the whole library with another superset language to add Typing for a simple library like react-timer-hook
Anyways since option 3 will make the library usable by TypeScript without any down sides for anyone to use the library it will really help if you could help with that option.
Thanks
from react-timer-hook.
Related Issues (20)
- Is there a way to manually set the time in useStopwatch?
- Just a question HOT 1
- useStopwatch not working HOT 1
- useStopwatch hook is causing continuous rerender HOT 2
- useStopwatch reset with offsetTimestamp always restarts at 0 HOT 2
- restart Function not working as Expected HOT 11
- Handling multiple timers
- multiple onExpire calls when the function is asynchronous HOT 2
- Is it possible to integrate intervals that have sound in the timer?
- Please support UTC time
- Start function in UseStopwatch Demo not working as Expected HOT 1
- Unnecessary re-rendering HOT 1
- Does this handle on focus window? HOT 1
- react native install issues HOT 1
- useStopwatch and useTime args are required HOT 1
- Please support returning miliseconds HOT 9
- How to get the current time on any event? HOT 1
- useTimer pause issue. HOT 1
- How to set useTimer to get seconds upper than 60s, HOT 1
- TS error Property 'totalSeconds' does not exist on type 'StopwatchResult' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-timer-hook.