当运行amplify serve
来本地测试我的React. js/ Typescript应用程序时,我从amplify库中得到了typescript错误。
扩增和键入库版本(package.json
片段):
{
"dependencies":
{
"@aws-amplify/core": "^5.1.12",
"@aws-amplify/ui-react": "^4.6.0",
"@aws-amplify/ui-react-storage": "^1.1.0",
"aws-amplify": "^5.1.3",
"typescript": "^3.8.3",
}
}
tsconfig.json
内容:
{
"compilerOptions": {
"target": "es5",
"lib": ["es6", "dom", "dom.iterable", "esnext" ],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"plugins": [{ "name": "typescript-plugin-css-modules" }],
"jsx": "react",
},
"include": ["src"],
"exclude": ["node_modules", "node_modules/*", "node_modules/**",
"./node_modules", "./node_modules/*" ]
}
我从amplify代码中得到的一些类型脚本错误:
ERROR in node_modules/@aws-amplify/core/src/Hub.ts:82:34
TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
80 | this.patterns = [...this.patterns.filter(x => x !== pattern)];
81 | } else {
> 82 | const holder = this.listeners[channel];
| ^^^^^^^
83 | if (!holder) {
84 | logger.warn(`No listeners for ${channel}`);
85 | return;
ERROR in node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts:33:10
TS2564: Property '_config' has no initializer and is not definitely assigned in the constructor.
31 | level: LOG_TYPE | string;
32 | private _pluggables: LoggingProvider[];
> 33 | private _config: object;
| ^^^^^^^
34 |
35 | /**
36 | * @constructor
ERROR in node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts:80:4
TS2322: Type 'null' is not assignable to type 'string'.
78 | let logger_level_name = this.level;
79 | if (ConsoleLogger.LOG_LEVEL) {
> 80 | logger_level_name = ConsoleLogger.LOG_LEVEL;
| ^^^^^^^^^^^^^^^^^
81 | }
82 | if (typeof (<any>window) !== 'undefined' && (<any>window).LOG_LEVEL) {
83 | logger_level_name = (<any>window).LOG_LEVEL;
为什么我会从Amplify得到错误,如何忽略、删除或修复它们?
1条答案
按热度按时间mwg9r5ms1#
我设法克服了错误,但我对我的答案不满意。
我会 * 喜欢 * 一个更好的答案,这不会关闭这些检查我自己的代码。
我能够通过
tsconfig.json
更新typescript,以抑制/不生成整个项目中的一些错误。(Is有没有一种方法可以只对库代码执行此操作?).