Tips and tricks for vue with typescript
I’ve been working on a vue project with typescript for almost a year now. Along the way, we found a few little things that I would like to share. Everything shown here is buried in vue’s documentation somewhere, you may need to dig a little, but it is all there. Note that all examples below use single file components and typescript 3. The project was created using vuecli 3. #1 typing $store and $refs in vue component When using the $store or $refs in a component, there is no typing available due to how vue wire the component together. You can, however, use regular typescript typing in the component class. The only catch is that since vue is assigning values to the properties you create, you need to use the ! operator in the property. This signals the transpiler that this property is going to be set and no warnings need to be issued. Additionally, this approach allows you to easily call methods from imported components which is sweet. ...