Development environment
MacBookAirM1 & Cursor
GitHub
https://github.com/terisuke/corsweb
When I linked up with Firebase and used npm run build to deploy with Hosting, the following error occurred and I was unable to build.
Property 'isDark' does not exist on type '{}'.
What I tried
Create types folder and types.d.ts and use global scope to define dark mode using $store property
types/types.d.ts // Alpine.jsを起動するためのメソッド start: () => void; } // Alpineインターフェースのインスタンスを作成します。 const alpine: Alpine; // alpineインスタンスをエクスポートします。 export = alpine; } declare global { // Windowインターフェースを拡張します。これにより、Alpine.jsの機能をグローバルスコープで使用できます。 interface Window { // Alpine.jsの型をインポートして、WindowオブジェクトにAlpineプロパティを追加します。 Alpine: typeof import('alpinejs').Alpine; } // Alpineインターフェースを拡張します。これにより、Alpine.jsのストア機能を使用できます。 interface Alpine { // $storeプロパティを追加します。これはAlpine.jsの状態管理機能を提供します。 $store: { // themeオブジェクトを追加します。これはテーマ関連の状態を管理します。 theme: { // isDarkプロパティはダークモードが有効かどうかを示します。 isDark: boolean; // toggleメソッドはダークモードを切り替えるための機能を提供します。 toggle: () => void; }; }; } }
Reviewed tsconfig.json and rewrote the contents to reflect the types file.
tsconfig.json { "extends": "astro/tsconfigs/strict", "compilerOptions": { "typeRoots": ["./node_modules/@types", "./types", "./src"], "types": ["types"] } }
Result
The following error occurs in Layout.astro and it cannot be built.
Property 'isDark' does not exist on type '{}'. 63 toggle() { 64 this.isDark = !this.isDark; ~~~~~~ 65 localStorage.setItem('theme', this.isDark ? 'dark' : 'light');
Has anyone had a similar error? Does anyone know the solution to this error?