【发布时间】:2020-01-29 12:24:20
【问题描述】:
使用 Typescript 3.* 和 momentjs 作为日期 我得到了编译时错误。
错误:(3, 13) TS2349: 无法调用其类型缺少调用签名的表达式。类型“typeof moment”没有兼容的调用签名。
所以,我寻找解决此错误的解决方案。 并找到以下文章, 我做了与文章中描述的解决方案相同的事情。
但我又遇到了编译时错误。
错误:(1, 8) TS1192:模块 '"/Users/hogehoge/Work/Work_Fork/hoge/node_modules/moment/moment"' 没有默认导出。
这是我的 tsconfig 和我的程序。
{
"compilerOptions": {
"moduleResolution": "node",
"skipLibCheck": false,
"target": "es5",
"module": "commonjs",
"lib": ["es2017", "dom"],
"experimentalDecorators": true,
"allowJs": false,
"jsx": "react",
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"removeComments": true,
"newLine": "LF",
"downlevelIteration": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": false
},
"exclude": ["node_modules"]
}
import moment from 'moment';
console.log(moment().format('YYYY-MM-DD'))
【问题讨论】:
标签: typescript