我正在使用ngc
编译器提前编译我的Angular 2应用程序。在我的应用程序的一部分中,我使用Notification API,默认情况下,TypeScript不包含此API。当我运行ngc
时,它会抱怨:
c:\xampp\htdocs\project\_dev>"node_modules/.bin/ngc" -p tsconfig.aot.json
Error: Error at c:/xampp/htdocs/project/_dev/src/app/shared/notify.service.ts:34:17: Cannot find name 'Notification'.
Error at c:/xampp/htdocs/project/_dev/src/app/shared/notify.service.ts:35:17: Cannot find name 'Notification'.
Error at c:/xampp/htdocs/project/_dev/src/app/shared/notify.service.ts:35:61: Cannot find name 'NotificationPermission'.
Error at c:/xampp/htdocs/project/_dev/src/app/shared/notify.service.ts:56:36: Cannot find name 'Notification'.
at check (c:\xampp\htdocs\project\_dev\node_modules\@angular\tsc-wrapped\src\tsc.js:31:15)
at Tsc.typeCheck (c:\xampp\htdocs\project\_dev\node_modules\@angular\tsc-wrapped\src\tsc.js:86:9)
at c:\xampp\htdocs\project\_dev\node_modules\@angular\tsc-wrapped\src\main.js:33:23
at process._tickCallback (internal/process/next_tick.js:103:7)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
Compilation failed
我有一个用于window.Notification对象及其方法的自定义TS定义文件,但是如何告诉ngc编译器这个文件在哪里?
我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"outDir": "./compiled"
},
"files": [
"./src/app/app.module.ts",
"./src/main.aot.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
}
}
答案 0 :(得分:2)
想出来:
<cms:DocumentAttachments ID="ucDocAttachments" runat="server" TransformationName="cms.root.attachment" Path='<%# Eval("NodeAliasPath") %>' />
; custom_typings
的子文件夹,其中包含一个名为notification
的字段,其中包含我的自定义TS定义; index.d.ts
compilerOptions
编译器会自动拾取它,一切都很好。