描述
在角度 10 中,下面是我的 ts-config。
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictTemplates": true
}
}
当我尝试为我的应用程序提供服务时,我面临以下问题:
ERROR in src/app/app.component.ts:8:14 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
8 <button (created)="oncreate($event)" ejs-button>Button</button>
但是当我设置strict:false
它工作正常。
最小复制
- 从以下链接下载示例 严格模式 sample.zip
npm i
那就给ng serve
异常或错误
D:\incidents\strict mode sample>ng serve
'wmic.exe' is not recognized as an internal or external command,
operable program or batch file.
(node:17616) ExperimentalWarning: The fs.promises API is experimental
Compiling @angular/core : es2015 as esm2015
Compiling @angular/animations : es2015 as esm2015
Compiling @angular/compiler/testing : es2015 as esm2015
Compiling @angular/animations/browser : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/core/testing : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Compiling @angular/common/testing : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/platform-browser/testing : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/animations/browser/testing : es2015 as esm2015
Compiling @angular/common/http/testing : es2015 as esm2015
Compiling @angular/platform-browser/animations : es2015 as esm2015
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
Compiling @angular/router/testing : es2015 as esm2015
Compiling @syncfusion/ej2-angular-buttons : es2015 as esm2015
Compiling @syncfusion/ej2-angular-grids : es2015 as esm2015
chunk {main} main.js, main.js.map (main) 2 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 677 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 341 kB [initial] [rendered]
Date: 2020-08-04T10:45:29.294Z - Hash: d04b0cca85382beb066d - Time: 29909ms
ERROR in src/app/app.component.ts:8:14 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
8 <button (created)="oncreate($event)" ejs-button>Button</button>
你的环境
"@angular/animations": "~10.0.6",
"@angular/common": "~10.0.6",
"@angular/compiler": "~10.0.6",
"@angular/core": "~10.0.6",
"@angular/forms": "~10.0.6",
"@angular/platform-browser": "~10.0.6",
"@angular/platform-browser-dynamic": "~10.0.6",
"@angular-devkit/build-angular": "~0.1000.5",
"@angular/cli": "~10.0.5",
"@angular/compiler-cli": "~10.0.6",
来自角度团队的建议,
https://github.com/angular/angular/issues/38342#issuecomment-668753033
任何人请建议我,如何替换我的 82 事件行的typedef
我正在注册他们提到的事件,