Use TypeScript on Nuxt.js from v2.5

You can use TypeScript naturally in Nuxt now

Kengo Hamasaki / hmsk
Hai-iro

--

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.

--

--