簡體   English   中英

為什么 Snowpack 不接受我的類型聲明文件?

[英]Why Snowpack is not taking my type declaration files?

我在雪包中有以下配置:

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
        public:{ url: '/', static: true },
        src: { url: '/dist' },
        runtime: { url: '/runtime' },
  },
  plugins: [
        '@snowpack/plugin-typescript',
        ['@snowpack/plugin-babel', 
            {
                'input': ['.ts', '.tsx'],
            }
        ]
  ],
  packageOptions: {
    /* ... */
  },
  devOptions: {
    /* ... */
  },
  buildOptions: {
    /* ... */
  },
};

這在我的聲明文件index.d.ts中,但是當我啟動開發服務器時,Snowpack 沒有讀取它。

declare global {
    namespace JSX {
        interface IntrinsicElements {
            [elName: string]: any;
        }
    }
}

讓它工作的唯一方法是將文件名更改為index.ts

您提出問題的方式 - snowpack '不采取' your.d.ts 文件 - 對我來說有點含糊。 如果您的意思是您的編輯器(假設 VSCode)沒有給您自動完成功能,請嘗試將文件添加到 tsconfig.json 中的“包含”數組中:

{
    "include": [
        ...
        "index.d.ts",
    ]
}

我從 create-snowpack-app CLI 工具使用的基本 typescript 模板中找到了這個解決方案: https://github.com/snowpackjs/snowpack/tree/main/create-snowpack-app/app-template-blank-typescript .d.ts 文件位於“types”文件夾中,然后該文件夾包含在 tsconfig 中。

這里有一個關於它的線程: https://github.com/withastro/snowpack/discussions/1589

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM