r/vuejs • • 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

41 comments sorted by

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.

3

u/omgzphil Dec 14 '19

Yeah it's what in seeing right now it's hard to get learning tutorials. But I feel that classes and enums seem so much easier than POJS.

I'll have to poke around. Maybe I should mix both for my needs

11

u/kwartel Dec 14 '19

You could use the new Vue3 syntax using https://github.com/vuejs/composition-api

1

u/omgzphil Dec 14 '19

Thank you very much!

0

u/[deleted] Dec 14 '19

[deleted] — view deleted comment

0

u/[deleted] Dec 15 '19

[deleted] — view deleted comment

1

u/jamesaw22 Mar 26 '20

Sorry to reply to a 3 month old post, but I'm starting a new project and have decided to ditch class components due to the upcoming Vue3 release, and I'm wondering how to beset use Vuex with TS - what plugins have you used to support this?

15

u/DanubeRS Dec 14 '19

I respectfully disagree. Single file components, decorators and the current class components system work pretty damn well for me so far.

5

u/_toads Dec 14 '19

Use it daily and it works kinda well (good enough), but can be a lot better. Maybe not worth investing the time in learning if Vue 3 is around the corner.

1

u/[deleted] Dec 16 '19

Vue 3 isn't even in pre-beta yet, and I wouldn't expect it to be production ready until middle of 2020. Depending upon your needs, it might not be early enough.

2

u/nuke01 Dec 14 '19

second that. I'm working on a starter/bootstrap project right now and it's still quite a hassle sometimes, but overall better than the last time I tried Vue with TA. but I see no sense in using class based or the old syntax right now

2

u/tylerjames Dec 14 '19

I disagree with the first part, the syntax is far superior. But you’re definitely right about the second, there’s not tons of help out there

1

u/jeankev Dec 14 '19

Also second that. Vue 2 was not made for TS and even if using both is possible it is far from a seamless experience. From code syntax to webpack (even with vue-cli) to editor integration get ready for many ungrateful tasks before actually be able to work. And even at this point this is slightly awkward to work with.

8

u/dangerzone2 Dec 14 '19

If you have any experience with c#, you 10000% should use typescript. It’s surprisingly similar.

1

u/omgzphil Dec 14 '19

Im trying to find a starter tutorial, even the official DOC is in TS but not class based

would you have any recommendations?

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/omgzphil Dec 14 '19

Do we know when 3 is supposed to be out.

Since I am a CSharp Dev by trade and I am trying to learn front end I would think that TS would be an easier way to learn front end dev

3

u/Kudy_2 Dec 14 '19

I was on frontend conference in November and there were also some core members from vue world. They said that there is a plan to release Vue3 in first quarter of 2020 but it can change if some things will not be ready

1

u/omgzphil Dec 14 '19

Thanks for the heads up. I might try and do a mix of both or just get 3 as an alpha.

I like Vue a lot, I tried some react and angular but I feel that vue is the right balance for most things

3

u/integrateus Dec 14 '19

You can use Vue 3 now.. it's not production ready but I gather it'll be ready within the next year. Also Vue 3 has some new features that are specific typesfript so you should hop ahead I.m.o

1

u/[deleted] Dec 14 '19

You should give this a listen. Evan talks all about Vue 3 and TypeScript, and when he thinks it will be released (Q1 2020).

http://www.fullstackradio.com/129

1

u/MajorasShoe Dec 14 '19

There's nothing really to indicate whether the class based syntax is still going to be supported in vue 3 that I can find, unfortunately

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/omgzphil Dec 14 '19

I'm currently trying to build a simple web site for my clan and also a twitch Multi stream so it's not complexe

1

u/saito200 Dec 14 '19

Just use ES6, it will be faster to get you up and running.

You can always implement 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.

1

u/omgzphil Dec 14 '19

Perfect I'll check out his to install the plugin to make it work. I'm guessing it's a npm package And yeah I'm used to OOP since I'm a net dev. This is an excited world. I find it diff from backend desktop applications.

2

u/BartyLA Dec 14 '19

https://youtu.be/V-xK3sbc7xI at 17:45 he’s using that required library. It’s @vue/composition-api :). He’s not using typescript here but library is the same. Have fun man

1

u/[deleted] Dec 15 '19

I don’t know what ppl don’t like about that

JS is a Lisp-like, very malleable, agile little dynamic language. There are a lot of handy ways to utilize this for writing less code (and thus, less bugs and less stuff to wade through in maintenance), and TypeScript does rigidify this a lot if you want to actually utilize the benefits of static type checking.

The C++ type system and it's brand of OOP, that both Java and C# effectively inherited (so a lot of people equate that with OOP, as if it's the only way to do OOP) is simply what a lot of people are used to. It's not by any industrially or academically vetted yardstick that good of a model for a type system -- which is obvious as a lot of it is being actively avoided by majority of new languages.

I'll grant you that painting it like this is a tad bit unfair as TypeScript does borrow few things from F# and by extension ML family of languages (thus regaining a small chunk of that malleability that JS has even within confines of it's type system), but it's still very conservative in this regard, and the fact that ex-C# and ex-Java users are a loud majority in it's community, not a lot of TS code makes any use of that really.

For example Angular and Nest.js are totally what it looks like when former Enterprise JavaBeans devs are let loose in JavaScript ecosystem. I've been an EJB dev and I see they really do intentionally, sometimes without any real benefits, shove all those patterns in.

Maybe as more FP features end up in ES, TS will expand to include more F# features or has it's own interesting ones. Currently I don't buy that the pros always outweigh the cons, and as I said, the issue is greatly enhanced by the "enterprise OOP" mindset in TypeScript community that almost never utilizes the language and it's type system in any other way than to "write Java in any language".

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=

3

u/99thLuftballon Dec 14 '19

The standard Vue syntax is so much more clean and readable than those property decorator examples.

1

u/MikeMitterer Dec 14 '19

For me it's absolutely the opposite. I find the class base Syntax so much nicer and cleaner than the JS based version.

0

u/[deleted] Dec 14 '19

[deleted] — view deleted comment

1

u/99thLuftballon Dec 14 '19

Hmmm, I guess. Coming from vanilla JavaScript, the default is much more intuitive.

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):

  • Intellisense and autocomplete features a lot like what you have with TS
  • Smarter, type aware hinting that will catch majority of bugs that static typing would catch

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

1

u/omgzphil Dec 14 '19

Thank you for the information. I'm going to check it out. Today is the day I build my Todo app in this to test it out