Hey,
Is it possible to write formik in regular js instead of typescript and keep typings in a separate folder/file/library?
It's really hard to read the codebase and contribute when you don't know typescript. There are a lot of any typings, probably half - this kinda kills the purpose of strong types.
Currently, typescript adds to formik:
cons
anypros
any typings)This reminds the situation with coffescript - very hard to contribute, only for devs who know it. It'll be really great to have formik in plain js, is it possible?
I鈥檝e thought about this a few times over the last several months. There are other benfefits to being written in JS too...
First, maintaining backwards compat in TS is more challenging when you are writing in TS. I learned this when trying to figure out how to type 0.9. Technically, the types for withFormik should have been identical to 0.8, but because of being written natively in TS I had to introduce a default any value to a generic.
Second, Formik doesn鈥檛 show up on GitHub鈥檚 rankings as JS, but under the TS language category. This has probably had a nontrivial impact on popularity.
Cognizant of the points above and the ones you鈥檝e raised, I still don鈥檛 think moving to JavaScript is the path forward:
@jaredpalmer is it possible (in TS land) to have formik codebase in js and all TS typings in another file so you can import them in projects written in TS?
Comparing the number of pros and cons, I don't understand the purpose of TS in formik even more.
Yes, but this inevitably leads to bad code and more bugs. Types are your friend. In fact, Formik development has accelerated dramatically because of TS.
@sexualmaniac Previously, I tried flow, but it didn't go well with atom. After working with typescript in formik, I'm pretty sure I won't use it again - the code looks so ugly and so dirty.
Although it probably won't happen, I also wish formik was written in regular es6, looking at typescript code makes me wanna 馃槶 馃敨
@jaredpalmer the number of wrong type bugs (don't forget any typings) is very little compared to other types of bugs you'll see in a real-life app. Plus, this type checks in formik are only useful for devs, who use TS in their projects - they bring nothing to devs, who use plain js.
On the other hand, the overhead and code noise is insane - formik.tsx has almost 200 lines of code just for types - it's almost 30% of the whole file. Proper tests would serve a much better job and won't add code noise. Do you really need this overhead for formik to work well?
I highly recommend you to read this article - https://medium.com/javascript-scene/you-might-not-need-typescript-or-static-types-aa7cb670a77b, maybe it'll change your opinion on TS a bit, especially in open-source projects.
This is certainly not the place for a religious war on the merits of static-typing versus duck-typing, but I can say that @jaredpalmer and I are both fairly experienced JS developers, and after a year with the benefits of TypeScript in our projects -- the fewer tests we have to write, the clarity and self-documentation, the mistakes we catch early, the ease of sharing data models with our backend, the refactoring and autocomplete in VSCode -- I'd be very reluctant to ever go back to building anything in plain ES6.
Much of the community and many of the best companies in the space are moving in this direction also, so I don't think this is just our own weird preference. There's no accounting for taste, and use whatever works for you, but I'd recommend giving TypeScript a shot.
If it helps, just think of the types as documentation. Yes, the first ~172 lines of formik.tsx are type definitions, but most of that is comments.
My personal wish would be to get rid of the duplicative prop-types, but I think we need them to retain HOC compatibility.
@jaredpalmer Please, keep on using Typescript.
Somehow, it makes me laugh (no offence, not targeted to any particular person in this thread) this conversation exists here, or any other place.
I disagree typings are deal breakers for contributors. Even junior members in our teams have no problem with understanding Flow typings at all.
Biggest strength of static type checkers is discovering issues without running code, so as long I/you/we discover those with TS/Flow, we should keep on using them. Removing TS would be definitely step back.
Waiting for Reason to gain more traction 馃槑
@Andreyco I meant I think i can just remove these https://github.com/jaredpalmer/formik/blob/master/src/formik.tsx#L186
Got you. You can definitely remove them ;)
@eonwhite Thank you. Formik is the choice for many devs new to the React ecosystem (and JS for that matter), so we're grateful that it is somewhat opinionated with best practices based on your experience.
@ArlingtonHouse @sexualmaniac @Andreyco I am working on a React x TypeScript styleguide much like Airbnb's for ES6. Stay tuned.
@jaredpalmer just wanted to chime in and say that I fully support staying with typescript.
Yeah typescript rocks. Please stay with it.
@jaredpalmer @eonwhite what had take you to TS instead Flow for big business projects? Much cleaner code, VS support, prefer OOP style ?
The size, and growth trend, of TypeScript's community dwarfs Flow's. It's not really a contest.
VSCode's excellent support for TypeScript is a factor too.
We actually started building something on Flow last year and quickly pulled the plug and switched to TypeScript. Haven't looked back.
fun to read this 2 years on :)
FYI if Reason supported an HoC pattern, Formik would be written in Reason
@jaredpalmer, what are your thought on this today ?
Most helpful comment
fun to read this 2 years on :)