首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用qunit在TypeScript中将函数参数声明为"QUnit“类型?

如何使用qunit在TypeScript中将函数参数声明为"QUnit“类型?
EN

Stack Overflow用户
提问于 2019-05-14 03:12:31
回答 1查看 100关注 0票数 1

我在一个麻省理工学院许可的项目中使用了QUnit,其中一部分是用TypeScript编写的。我有一些TS函数,它们接受QUnit作为参数,并希望从the typing中键入它们作为其接口

例如:

代码语言:javascript
复制
import { QUnit } from "qunit";


export function run_tests(q: QUnit)
{
    q.module((a) => { ... });
}

然而,当我尝试的时候,我得到了这个错误:

代码语言:javascript
复制
tsc --project lib/typescript/www/tsconfig.json
src/ts/web-fc-solve-tests.ts(12,23): error TS2306: File '/home/shlomif/progs/fre
ecell/git/fc-solve/fc-solve/site/wml/node_modules/@types/qunit/index.d.ts' is no
t a module.

下面是我的代码(注意分支):https://github.com/shlomif/fc-solve/tree/qunit-typescript - it在fc-solve/site/wml子目录下。

我的tsconfig.json是:

代码语言:javascript
复制
{
  "compilerOptions": {
      "baseUrl": ".",
      "esModuleInterop": true,
      "module": "amd",
      "moduleResolution": "node",
      "noImplicitReturns": true,
      "outDir": "../../../lib/out-babel/js",
      "paths": {
          "big-integer": ["node_modules/big-integer/BigInteger.d.ts"],
          "qunit": ["node_modules/@types/qunit"]
      },
      "target":"es6"
  },
  "include": ["../../../src/ts/**/*.ts"]
}

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-14 04:35:12

如果你只需要输入,安装@types for qunit with npm应该是你需要做的全部事情,只需完全省略import语句。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56118562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档