如何为umd库创建TypeScript定义文件(d.ts)

duo*_*dvk 7 typescript definitelytyped webpack umd

我正在进行图书馆调查

它使用gulp + webpack来构建umd包.

我想创建类型定义包(或者可能只是多个d.ts文件),以便在typescript项目中使用.我想有类似的东西:

import * as Survey from 'surveyjs';
Run Code Online (Sandbox Code Playgroud)

此处描述了Survey.*的所有争议:https: //github.com/dmitrykurmanov/surveyjs/blob/master/src/entries/ko.ts

我曾尝试使用:github.com/SitePen/dts-generatorgithub.com/TypeStrong/dts-bundle,但没有成功,有人可以告诉我正确的方向吗?

tos*_*skv 6

您可以通过在tsconfig.json中添加声明标志,让tsc为您的代码生成声明文件.

在你的情况下,它将是:

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "sourceMap": true,
    "noImplicitAny": false,
    "jsx": "react",
    "declaration": true
  },
//  "filesGlob": [
  //    "typings/index.d.ts"
  //  ], // TODO
  "include": [
    "typings/index.d.ts",
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

  • 是的。webpack-stream 输出中的问题。它只是 js 包,但我怎样才能得到 d.ts?所以我单独运行'gulp-typescript'编译器并生成d.ts。这不酷。 (3认同)