Use TypeScript on Nuxt.js from v2.5

You can use TypeScript naturally in Nuxt now

Image for post
Image for post

Writing this article to revise my previous article about Nuxt+TS. Some people who read this article had misunderstood as that nuxt-ts is still available to use TypeScript on Nuxt.

Currently, this article is valid until Nuxt 2.5–2.8.1 (June 4th, 2019). After 2.9, the official maintains the new way to support TypeScript on Nuxt. So this article is not worth reading anymore 😉

tl;dr

  • To use TypeScript on Nuxt, install ts-node
  • May need some typedefs for Nuxt features, then install @nuxt/typescript, @types/node, then put @nuxt/vue-app and @types/node to tsconfig.json on the project root

Samples

As I mentioned in the previous article, I’m now maintaining this repo. I’m keeping Nuxt’s version up-to-date in my some projects, and try to show the most minimum sample on the template.

Official repo is also having some samples on examples dir (Search the page with typescript.

And create-nuxt-app is about to support TypeScript project.

Originally, I tried to contribute to create-nuxt-app , but gave up by thinking about writing TypeScript for the crazy number of cases which create-nuxt-app had been already supporting.

So, may put some basic samples (like ESLint, testing, plugins, middlewares…etc) on @nuxt-community/typescript-template instead. (Or build create-nuxt-ts-app? but I’d to learn why create-react-ts-app had gone firstly)

From Nuxt 2.5

No more nuxt-ts, write everything with ".ts"

nuxt-ts was just only for 2.4 at all 😂. We can just use nuxt package/command even for we’d to use TypeScript. ts-node is required instead.

Enable plugins/*.ts, modules/*.ts, middleware/*.ts and nuxt.config.ts

🎉

Typedefs are mostly provided

To have typings for Nuxt-ish things for example asyncData, fetch on the components. Add @nuxt/vue-app (provided by @nuxt/typescript npm module) on tsconfig.json. Your custom d.ts may be no longer needed.

Hai-iro

A Japanese duo by a product designer and a software…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store