【发布时间】:2019-01-29 00:50:10
【问题描述】:
使用 JSDoc 扩展 jest.Matchers 的文档
我写了一个简单的 jest.Matchers 扩展,但我无法让 typescript 类型检查器识别我的扩展。
我使用的是纯 JavaScript。
// @ts-check
const getFunctorValue = F => {
let x
F.fmap(v => x = v)
return x
}
expect.extend({
/**
* @extends jest.Matchers
* @param {*} actual The functor you want to test.
* @param {*} expected The functor you expect.
*/
functorToBe(actual, expected) {
const actualValue = getFunctorValue(actual)
const expectedValue = getFunctorValue(expected)
const pass = Object.is(actualValue, expectedValue)
return {
pass,
message () {
return `expected ${actualValue} of ${actual} to ${pass ? '' : 'not'} be ${expectedValue} of ${expected}`
}
}
}
})
/**
* @constructor
* @param {*} v Any value
*/
function just (v) {
return {
fmap: f => just(f(v))
}
}
describe('Functor Law', () => {
test('equational reasoning (identity)', () => {
expect(just(1)).functorToBe(just(1))
})
})
但是符合expect(just(1)).functorToBe(just(1)),
我在functorToBe 下看到一条红色下划线,并显示以下错误消息:
[ts] 属性 'functorToBe' 不存在于类型 'Matchers any; }>'。 任何
我通过在vscode 中写入expect() 得到jest.Matchers,并查看了描述。
更新:我终于在 typescript repo 中提交了一个错误报告:https://github.com/Microsoft/TypeScript/issues/26675
【问题讨论】:
-
我刚刚找到Using Jest with TypeScript。也许会有一些东西可以帮助解决这个问题。
-
不,那里什么都没有。安装打字稿等不会改变任何东西。
标签: javascript jestjs jsdoc