错误 TS2552:找不到 @types/winrt-uwp 的名称 'Windows'
error TS2552: Cannot find name 'Windows' for @types/winrt-uwp
在 angular 6 个项目中 os 在 windows 10 os、
中完成
我启动命令:
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);
}
}
但是当我想启动项目时出现错误信息:
error TS2552: Cannot find name 'Windows'. Did you mean 'Window'?
但是我可以创建一个包含
的文件 node_modules/@types/winrt-uwp/index.d.ts
...
declare namespace Windows {
...
}
..
你知道这个问题吗?
要能够使用 winRT 功能,您必须在文件顶部添加此代码 maint.ts
/// <reference types="@types/winrt-uwp" />
并以这种方式配置 angular.json
"options": {
...
"index": "src/index.html",
"main": "src/main.ts",
...
},
在 angular 6 个项目中 os 在 windows 10 os、
中完成我启动命令:
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);
}
}
但是当我想启动项目时出现错误信息:
error TS2552: Cannot find name 'Windows'. Did you mean 'Window'?
但是我可以创建一个包含
的文件node_modules/@types/winrt-uwp/index.d.ts
...
declare namespace Windows {
...
}
..
你知道这个问题吗?
要能够使用 winRT 功能,您必须在文件顶部添加此代码 maint.ts
/// <reference types="@types/winrt-uwp" />
并以这种方式配置 angular.json
"options": {
...
"index": "src/index.html",
"main": "src/main.ts",
...
},