0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

laravel9.x inertia vue3.2でsetup+lang="ts"での対応

Posted at

laravel + inertia + vue3.2で
vueファイル内のスクリプトタグを<script setup lang="ts">とすると
laravel-echoをimportしているファイルで
Module cannot などエラーが出るため対応。
予め、resources/js/@typesフォルダを作っておく。

tsconfig.jsonの設定

色々変えたのでどこが肝かわからないので一通り設定を記載する。

tsconfig.json
{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "baseUrl": "./",
     "typeRoots": [
        "./resources/js/@types"
    ],
    "types": [
      "node"
    ],       
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": false,
    "skipLibCheck": true
  },
  "include": [
    "./resources/js/**/*"
  ]
}

window.Pusherとwindow.Echoを別のtsファイルでも使えるようにするため
resources/js/@typesフォルダにファイルglobal.d.tsを作成する。

resources/js/@types/global.d.ts
interface Window {
  Echo: any;
  Pusher: any;
}
declare var window: Window;

これでとりあえずビルドも通ってlarave-echoのbroadcastの通知も来る。
他にいい方法がありそうだが。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?