Typescript 茉莉花/打字稿-使用';这';变量

Typescript 茉莉花/打字稿-使用';这';变量,typescript,jasmine,Typescript,Jasmine,在我们所有的Jasmine单元测试中,我们使用this变量在描述块中传递变量和方法,在每个之前使用和它: import { UnderTest } from './somewhere'; describe('#someMethod', () => { beforeEach(() => { this.param = []; this.run = () => UnderTest.someMethod(this.param); }); describe

在我们所有的Jasmine单元测试中,我们使用
this
变量在
描述
块中传递变量和方法,在每个之前使用

import { UnderTest } from './somewhere';

describe('#someMethod', () => {
  beforeEach(() => {
    this.param = [];
    this.run = () => UnderTest.someMethod(this.param);
  });

  describe('when nothing is provided', () => {
    it('returns an empty object', () => {
      expect(this.run()).toEqual({});
    });
  });
});
这在过去工作得很好,但一旦我们将Typescript依赖项升级到4.x.x,运行测试就会产生一个编译器错误,
对象可能是“未定义的”
,用于所有
引用


我们是Angular 10项目的一部分,我尝试在
tsconfig.spec.json
文件中添加
“strictNullChecks”:false
,但这似乎没有任何作用。现在在单元测试中使用
这个
是个坏主意吗?有什么方法可以保持Typescript的最新状态并抑制这些错误吗?

您希望
这是什么?在您显示的代码中,它始终是
未定义的
@AluanHaddad。该函数将通过Jasmine框架绑定到
。但它是一个箭头函数,发现了一个重复的问题,并给出了可接受的答案:您希望
是什么?在您显示的代码中,它将始终是
未定义的
@AluanHaddad。该函数将通过Jasmine框架绑定到
。但它是一个箭头函数,发现了一个重复的问题,并有一个可接受的答案: