如何增加@types/mocha? [英] How to augment @types/mocha?

查看:38
本文介绍了如何增加@types/mocha?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以无数不同的方式应用 Aluan 的

特别提到 this 作为 it 钩子的参数也不起作用:

it("should do something", async function (this: Mocha.Context) {...});

解决方案

最终由 Aluan 提供了解决方案.他原来的回答有一个小错误.

只需删除命名空间:

import { Foo } from './foo';声明模块摩卡"{导出接口上下文{富:富;}}

I tried to apply Aluan's answer in countless different ways, but none worked, that is, none gave me the sweet auto-complete for the types that I augmented:

augmentations.d.ts

import { Foo } from './foo';

declare module "mocha" {
  namespace Mocha {
    export interface Context {
      foo: Foo;
    }
  }
}

I made sure that the augmentations.d.ts file is part of a glob pattern in the include property of tsconfig.json, but this is all I see in VSCode when I type this in a test hook:

Specifically mentioning this as the argument for the it hook didn't work either:

it("should do something", async function (this: Mocha.Context) {
 ...
});

解决方案

The solution was eventually provided by Aluan. There was a minor typo in his original answer.

Just remove the namespace:

import { Foo } from './foo';

declare module "mocha" {
  export interface Context {
    foo: Foo;
  }
}

这篇关于如何增加@types/mocha?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆