Javascript 开玩笑不';不了解流类型和对象分解?
我一直在流类型和笑话中遇到这个错误:Javascript 开玩笑不';不了解流类型和对象分解?,javascript,babeljs,jestjs,flowtype,Javascript,Babeljs,Jestjs,Flowtype,我一直在流类型和笑话中遇到这个错误: TypeError: Cannot read property 'returnType' of undefined at builder (src/index.js:22:195) at Object.<anonymous> (__test__/index.spec.js:6:53) at process._tickCallback (internal/process/next_tick.js:103:7) .babelrc配置:
TypeError: Cannot read property 'returnType' of undefined
at builder (src/index.js:22:195)
at Object.<anonymous> (__test__/index.spec.js:6:53)
at process._tickCallback (internal/process/next_tick.js:103:7)
.babelrc
配置:
{
"presets": [
"es2015", "jest"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
],
"env": {
"test": {
"presets": [
"es2015", "jest"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
]
}
}
}
{
"bail": true,
"verbose": true,
"collectCoverage": true,
"coverageDirectory": "./coverage",
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
}
}
jest.json
config:
{
"presets": [
"es2015", "jest"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
],
"env": {
"test": {
"presets": [
"es2015", "jest"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
]
}
}
}
{
"bail": true,
"verbose": true,
"collectCoverage": true,
"coverageDirectory": "./coverage",
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
}
}
如果我将
{returnType='object'}
更改为options
,然后在方法中进行分解,它似乎可以完全正常工作。考虑到这一点,这是允许同时使用jest
和flow
类型的唯一方法吗?我更希望能够在签名中而不是在方法体中分解结构。查看您的错误,您可能无法将第二个参数传递给函数。如果您调用builder('foo')
,您将尝试在未定义的下对返回类型进行解构
使用第二个参数调用它:builder('foo',{})
,或者为参数提供默认值:
导出默认函数生成器(路径:字符串,{returnType='object'}:builderOptionType={}):BuilderReturnType{…}
查看错误,您可能无法将第二个参数传递给函数。如果您调用builder('foo')
,您将尝试在未定义的下对返回类型进行解构
使用第二个参数调用它:builder('foo',{})
,或者为参数提供默认值:
导出默认函数生成器(路径:字符串,{returnType='object'}:builderOptionType={}):BuilderReturnType{…}
ah,我认为{returnType='object'}:builderoptionType
足够了,我认为{returnType='object'}:builderoptionType
足够了