typescript 找不到SvelteKit PageLoad模块

0yg35tkg  于 2022-11-18  发布在  TypeScript
关注(0)|答案(1)|浏览(232)

我有一个SvelteKit项目,由于某些原因,./$types没有PageLoad模块(其他项目有。我不确定我做了/没有做什么没有它。这是我得到的错误:

Module '"./$types"' has no exported member 'PageLoad'.ts(2305)

这是我如何使用它(用于测试):

import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params, fetch }) => {
  console.log('props from +page.ts: ', params.db_item)
  // We fetch the post here using a Worker/Lambda
  return params.db_item
}

下面是我的package.json文件:

{
    "name": "test",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "dev": "vite dev",
        "build": "vite build",
        "preview": "vite preview",
        "test": "playwright test",
        "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
        "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
        "lint": "prettier --check .",
        "format": "prettier --write .",
        "surge deploy": "rollup -c; surge public"
    },
    "devDependencies": {
        "@playwright/test": "^1.25.0",
        "@sveltejs/adapter-auto": "next",
        "@sveltejs/kit": "next",
        "node-sass": "^7.0.3",
        "prettier": "^2.6.2",
        "prettier-plugin-svelte": "^2.7.0",
        "svelte": "^3.44.0",
        "svelte-check": "^2.7.1",
        "svelte-preprocess": "^4.10.6",
        "tslib": "^2.3.1",
        "typescript": "^4.7.4",
        "vite": "^3.1.0"
    },
    "type": "module",
    "dependencies": {
        "svelte-share-buttons-component": "^1.5.0"
    }
}

下面是我的svelte.config文件:

import adapter from '@sveltejs/adapter-cloudflare';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: preprocess(),

    kit: {
        adapter: adapter()
    }
};

export default config;

如果还有什么需要我提供的,请告诉我。谢谢!

tpgth1q7

tpgth1q71#

这绝对是疯了,但我想通了。
我最初将文件命名为+page.js,并将其 * 重命名 * 为. ts。显然,这会打乱所有的事情。删除文件并 * 创建 * 扩展名为.ts的文件后,$types导入工作得很完美。文档中没有任何地方提到它,但它就是这样。

相关问题