Я пытаюсь заставить moment
работать в моем приложении angular
. Вот чистый пример репо , чтобы продемонстрировать проблему. Клонируйте этот репозиторий и запустите ng build test-library
в корневом каталоге. Сначала установите пакеты, npm install
.
Когда я пытаюсь использовать moment
, я получаю следующую ошибку. Что я делаю неправильно? Я пытался это исправить какое-то время. Я много раз гуглял и пробовал несколько предложений безрезультатно.
Использование:
import * as moment from 'moment';
...
public doSomething(): string {
const aMoment: moment.Moment = moment(); // line 22
return aMoment.format();
}
Ошибка:
projects/test-library/src/lib/test-library.component.ts(22,36): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof moment' has no compatible call signatures.
tsconfig.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"outDir": "../../out-tsc/lib",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}