hcastillo's avatar

How install Typescript to laravel 9 + inertia (vue3) ?

Hello, i'm trying to install typescript to my laravel 9 + inertia (vue3) app, but i cant do it in normal way.. Typescript is not recognized . Any guide or something?

0 likes
3 replies
drehimself's avatar
Level 35

I just installed Vue 3 / Inertia using the Breeze scaffolding and after a few simple changes, TypeScript seemed to work: https://laravel.com/docs/9.x/starter-kits#breeze-and-inertia

  • Rename app.js and bootstrap.js to app.ts and bootstrap.ts (and the vite.config.js file too, if you like)
  • In app.blade.php change the vite directive to point to the ts file: @vite('resources/js/app.ts')
  • In vite.config.ts change app.js to app.ts

In any Vue SFC, set the language to "ts" and start using TypeScript. For example, in Login.vue this worked for me:

<script setup lang="ts">

function sayHello(name:string): string {
  return `Hello ${name}`;
}

</script>

For specific TS related config, you might have to use a tsconfig.json file.

6 likes

Please or to participate in this conversation.