Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

typescript - Why Snowpack is not taking my type declaration files?

I have the following configuration in snowpack:

/** @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: {
    /* ... */
  },
};

And this is in my Declaration file index.d.ts but Snowpack is not reading it when I start the dev server.

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

The only way to get it working is changing the file name to index.ts

question from:https://stackoverflow.com/questions/66068214/why-snowpack-is-not-taking-my-type-declaration-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The way you've phrased the question - snowpack 'not taking' your .d.ts files - is a bit vague for me. If you mean that your editor (assuming VSCode) is not giving you autocompletion then try to add the file to the "include" array in your tsconfig.json:

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

I found this solution from the basic typescript template used by the create-snowpack-app CLI tool: https://github.com/snowpackjs/snowpack/tree/main/create-snowpack-app/app-template-blank-typescript There the .d.ts file is inside 'types' folder, and that folder is then included in tsconfig.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...