【问题标题】:SvelteKit, import type LayoutServerLoad/PageLoadSvelteKit,导入类型 LayoutServerLoad/PageLoad
【发布时间】:2022-11-17 16:10:21
【问题描述】:

在 layout.server.ts 我尝试

import type { LayoutServerLoad } from './$types';

但找不到类型:

'"./$types"' 没有名为 'LayoutServerLoad' 的导出成员。您指的是 'LayoutServerData' 吗?

我需要做什么才能在 ./$types 中获取类型 LayoutServerLoad(或 PageLoad 或 PageServerLoad ...)?

【问题讨论】:

    标签: sveltekit


    【解决方案1】:
    • 文件必须被称为+layout.server.ts(或者对于另一个加载操作,其他固定名称之一,see docs
    • Vite 开发服务器必须运行,它会监视文件并在文件更改时生成类型
    • tsconfig.json 必须扩展 .svelte-kit sconfig.json,它定义了 rootDirs,因此生成的类型已被解析。这应该已经是这种情况,根据对 LayoutServerData 的建议判断。)

    【讨论】:

    • 谢谢! (文件名中的 + 丢失。)
    • The Vite dev server has to be running, which watches the files and generates the types when a file is changed钥匙给我!
    猜你喜欢
    • 2022-11-02
    • 2023-01-11
    • 2022-11-16
    • 1970-01-01
    • 2023-02-18
    • 2023-02-26
    • 1970-01-01
    • 2022-10-20
    • 2021-11-16
    相关资源
    最近更新 更多