Angular 错误TS2552:找不到名称';视窗';对于@types/winrt-uwp
在windows 10操作系统中托管的angular 6项目中 我启动命令:Angular 错误TS2552:找不到名称';视窗';对于@types/winrt-uwp,angular,typescript,uwp,windows-runtime,angular6,Angular,Typescript,Uwp,Windows Runtime,Angular6,在windows 10操作系统中托管的angular 6项目中 我启动命令: npm install --save @types/winrt-uwp 它应该允许我使用winRT能力并编写代码: public showToast(message, iconUrl) { if ( typeof Windows !== "undefined" && typeof Windows.UI !== "undefined" &&
npm install --save @types/winrt-uwp
它应该允许我使用winRT能力并编写代码:
public showToast(message, iconUrl) {
if (
typeof Windows !== "undefined" &&
typeof Windows.UI !== "undefined" &&
typeof Windows.UI.Notifications !== "undefined"
) {
var notifications = Windows.UI.Notifications;
var template = notifications.ToastTemplateType.toastImageAndText01;
var toastXml = notifications.ToastNotificationManager.getTemplateContent(
template
);
var toastTextElements = toastXml.getElementsByTagName("text");
toastTextElements[0].appendChild(toastXml.createTextNode(message));
var toastImageElements = toastXml.getElementsByTagName("image");
var newAttr = toastXml.createAttribute("src");
newAttr.value = iconUrl;
var altAttr = toastXml.createAttribute("alt");
altAttr.value = "toast graphic";
var attribs = toastImageElements[0].attributes;
attribs.setNamedItem(newAttr);
attribs.setNamedItem(altAttr);
var toast = new notifications.ToastNotification(toastXml);
var toastNotifier = notifications.ToastNotificationManager.createToastNotifier();
toastNotifier.show(toast);
}
}
但当我想启动项目时,我会收到错误消息:
错误TS2552:找不到名称“Windows”。你是说“窗户”吗
但是,我可以创建一个文件node\u modules/@types/winrt-uwp/index.d.ts
,其中包含
...
declare namespace Windows {
...
}
..
您对这个问题有什么想法吗?要使用winRT功能,您必须在maint.ts文件的顶部添加此代码
/// <reference types="@types/winrt-uwp" />
"options": {
...
"index": "src/index.html",
"main": "src/main.ts",
...
},