14
src/env.d.ts
vendored
Normal file
14
src/env.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// 全局类型声明补充
|
||||
// @astrojs/alpinejs 集成会在运行时把 Alpine 挂到全局(window.Alpine),
|
||||
// 但 @types/alpinejs 是 CJS(export = Alpine),其顶层 declare const Alpine
|
||||
// 不会自动进入模块上下文(.astro 的 <script> 是模块),导致 IDE 报 “Cannot find name 'Alpine'”。
|
||||
// 这里用 namespace 导入取真实的 Alpine.Alpine 接口类型作为全局声明,
|
||||
// 既消除报错、又让 Alpine.data / .store / .magic 等方法以及 data 组件内的 this 都有完整提示。
|
||||
// 注意:@types/alpinejs 是 export = 形式,不能用默认导入(会解析成 namespace 而非类型)。
|
||||
import type * as Alpine from "alpinejs";
|
||||
|
||||
declare global {
|
||||
const Alpine: Alpine.Alpine;
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user