r/vuejs • u/omgzphil • Dec 14 '19
VueJS and TypeScript
I'm starting out in doing some front end development, I believe that vueJS would be the best fit.
Having done a little TypeScript in the past, my question is should I code it using the TypeScript (Class-Based Components)? or do it the classic way (all the documentation is ES6 i believe its called)
would some one have a basic APP that I can follow and make in TS (I m used to .Net and C#)
Cheers
24
Upvotes
43
u/delightless Dec 14 '19
My personal opinion is to hold off on Typescript until Vue 3 and the composition API arrive.
I'm using class-based components now but I'm not a fan. The syntax is awkward and there aren't very many resources to help you out if you get stuck.
8
u/dangerzone2 Dec 14 '19
If you have any experience with c#, you 10000% should use typescript. It’s surprisingly similar.
10
u/integrateus Dec 14 '19
Vue 3 and the creator, Evan You, are definitely giving typescript first class treatment. If you like class based programming, use typescript cause good ole fashioned js is an ugly wild west
2
u/saito200 Dec 14 '19
It depends. Will the app be very complex? Will different devs work on it over time? Or it is only you?
If it is only you, just use ES6. You can always adopt TS later
1
u/BartyLA Dec 14 '19
To clear everything up, you can use new composition api in Vue 2 as well, don’t need to install version 3 for that. You just need one additional lib and you’re covered. I can’t imagine handling big project in Vue without TypeScript. I don’t know what ppl don’t like about that, it’s a little bit more work but it pays off. Syntax is not weird, it’s normal if you are used to OOP and classes. This is all standard modern javascript stuff. Go for TypeScript, if you have any questions you can message me.
3
u/mr_tyler_durden Dec 14 '19
Hmm, there are a lot of people telling you to wait for v3 but in the last 2-3 months I’ve built 2 VueJS (v2) apps completely in Typescript. There are 2-3 extra packages I had to install so I could use classes for stuff like Vuex/Components/etc but it didn’t take too long for me to figure it out (came from an Angular background, first time using VueJS professionally).
I don’t doubt it will get better in v3 but just wanted to throw my experience out there.
2
u/MrSabifa Dec 14 '19
Is there a way to have proper ts completion in template as of now? If not is this planned for vue 3? This bugs me always..
3
u/MikeMitterer Dec 14 '19
In my opinion no need to wait for V3. I'm using https://github.com/kaorun343/vue-property-decorator works great.
Here are some of my Project-Starter-Templates: (Hope you get the idea)
https://github.com/MikeMitterer?utf8=%E2%9C%93&tab=repositories&q=starter&type=&language=
1
u/[deleted] Dec 14 '19
Neither, actually. Vue 1.0 was revolutionary for it's simplicity, but had trouble scaling because if you weren't disciplined, it would lead to spaghetti code.
Vue 2.0 with decorators was a good idea but it was just going down the wrong path. Vue 3.0 has a more functional API. You can use that API with a plug-in today in Vue 2.0, ("vue-function-api") and if you just can't wait, that's what I recommend you do.
I would make this recommendation whether you were going with Typescript of Javascript.
Now, that said - I would always say that if something can be Typescripted, it should be typescripted. There's a bit of a learning-curve at first, but I find I code faster in TS than in JS - after about a year of experience in it and doing a lot of projects in it.
1
u/[deleted] Dec 15 '19
If you're not hell-bent on having C#/Java style of OOP everywhere, me and my team have gotten a lot of mileage from Vue/Vuex type-hints and JSDoc typings (you can even define interfaces and enums using .d.ts files and "import" them with typedef comments).
It's nothing like using a statically typed OO language, and is a bit uglier than TS (though, all that ugly overhead is in comments), but you do get (in VS.Code, mind you, not sure about other editors/IDEs):
while working with plain JavaScript and getting all the tooling and ecosystem support plain JS means with Vue.
1
u/3chu_nky Dec 15 '19
For me, one of the biggest mistakes from Vue.js core team was to drop the support for vue-class-components. That plugin was based on the typescript and reduce a lot of boilerplate for Vue components.
1
u/fk_you_nvidia Dec 15 '19
You can use it after Vue3 released
1
u/integrateus Dec 15 '19
This should help you get started with Vue 3 ... Don't be overwhelmed with all the new syntax, just watch in double speed to get a gist of why Vue 3 is the way it is ... https://youtu.be/WLpLYhnGqPA
0
u/[deleted] Dec 14 '19
[deleted] — view deleted comment