简体   繁体   中英

Is it possible to generate TypeScript Type Definition/Declaration files?

So far I've tried to configure it in tsconfig.json

{
  "extends": "@tsconfig/svelte/tsconfig.json",

  "include": ["src/**/*"],
  "exclude": ["node_modules/*", "__sapper__/*", "public/*"],
  "compilerOptions": {
    "declaration": true,
    "outDir" : "public/lib" 
  }
}

and in the rollup.config.js

...
output: {
  sourcemap: true,
  format: 'iife',
  name: 'app',
  dir: 'public/lib',
},
...
typescript({ sourceMap: !production, declaration: true, declarationDir: 'public/lib' }),
...

Any ideas?

如果你需要创建全局类型,你可以在你的 src 文件夹中创建一个index.d.ts文件(例如),你在这个文件中添加的类型将在你的整个项目中可用,你不需要这样做任何其他事情。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM