How to augment @types/mocha? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-17 15:58:05

问题


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) {
 ...
});

回答1:


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;
  }
}


来源:https://stackoverflow.com/questions/62289629/how-to-augment-types-mocha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!