小编mat*_*rai的帖子

如何在 Typescript 中使用 Chai Expect() 验证特定类型?

我尝试在之前的帖子中寻找答案,但我还没有找到答案,所以这里是:

我目前正在尝试使用 Typescript 中 Chai 的 Expect() 来测试对象实例属性值的返回类型。到目前为止,我已经尝试过:

/* My type file */

export type customType = "one" | "two" | "three";
export default customType;

/* My test file */

import customType from '{path_to_customType}'; // 'customType' is declared but its value is never read.

const newObject = new Object({property1: value1}) //note: value1 is of type customType

describe("Class1 test", () => {
    it('my tests', () => {
        expect(newObject).to.have.property("property1").to.equal("value1"); //so far, this one works fine
        expect(newObject).to.be.a('customType'); // not working
        expect(newObject).to.be.an('customType'); // not …
Run Code Online (Sandbox Code Playgroud)

types mocha.js chai typescript typescript-generics

5
推荐指数
1
解决办法
2953
查看次数

Rust 结构体的 TypeScript 等价物是什么?

我已经用 TypeScript 编写了大约一年左右的时间,并且我在 Github 上发现了一个用 Rust 编写的不错的项目,我想将其包装在 TypeScript 中。我从未用 Rust 编程,但我有 C++ 经验。我相信标题中我的问题已经很清楚了。Rust 中的结构有点像 TypeScript 中的接口吗?

rust typescript

1
推荐指数
1
解决办法
1200
查看次数

标签 统计

typescript ×2

chai ×1

mocha.js ×1

rust ×1

types ×1

typescript-generics ×1