I'm new to Typescript. I just started an Ionic 1.2.4 (Angular) project using Typescript. When transpiling, I receive the error message Property 'Keyboard' does not exist on type 'CordovaPlugins'
due to the following function passed to angular.module.run()
in a file run.ts
我是Typescript的新手。我刚刚使用Typescript开始了一个Ionic 1.2.4(Angular)项目。转换时,我收到错误消息属性'Keyboard'在类型'CordovaPlugins'上不存在,因为以下函数传递给文件run.ts中的angular.module.run()
///<reference path="../../typings/tsd.d.ts"/>
export function onRun($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
})
}
The cordova plugin is in fact installed and it's type definition file definitely exists. Here is the file tsd.d.ts
.
实际上已经安装了cordova插件,它的类型定义文件肯定存在。这是文件tsd.d.ts.
/// <reference path="angularjs/angular.d.ts" />
/// <reference path="cordova/cordova.d.ts" />
/// <reference path="cordova/plugins/BatteryStatus.d.ts" />
/// <reference path="cordova/plugins/Camera.d.ts" />
/// <reference path="cordova/plugins/Contacts.d.ts" />
/// <reference path="cordova/plugins/Device.d.ts" />
/// <reference path="cordova/plugins/DeviceMotion.d.ts" />
/// <reference path="cordova/plugins/DeviceOrientation.d.ts" />
/// <reference path="cordova/plugins/Dialogs.d.ts" />
/// <reference path="cordova/plugins/FileSystem.d.ts" />
/// <reference path="cordova/plugins/FileTransfer.d.ts" />
/// <reference path="cordova/plugins/Globalization.d.ts" />
/// <reference path="cordova/plugins/InAppBrowser.d.ts" />
/// <reference path="cordova/plugins/Keyboard.d.ts" />
/// <reference path="cordova/plugins/Media.d.ts" />
/// <reference path="cordova/plugins/MediaCapture.d.ts" />
/// <reference path="cordova/plugins/NetworkInformation.d.ts" />
/// <reference path="cordova/plugins/Push.d.ts" />
/// <reference path="cordova/plugins/Splashscreen.d.ts" />
/// <reference path="cordova/plugins/StatusBar.d.ts" />
/// <reference path="cordova/plugins/Vibration.d.ts" />
/// <reference path="cordova/plugins/WebSQL.d.ts" />
/// <reference path="ionic/ionic.d.ts" />
/// <reference path="jquery/jquery.d.ts" />
I have also tried placing the type definition for Keyboard directly in run.ts
. ///<reference path="../../typings/cordova/plugins/Keyboard.d.ts"/>
我还尝试直接在run.ts中放置键盘的类型定义。 ///
I'm not expecting the plugin to actually register because 'cordova.js' is not available until the app is built/packaged. I would however like to know how to get Typescript to recognize that Keyboard
does in fact exist on cordova.plugins
via type defs. Otherwise, how can I avoid this error during transpilation?
我不希望插件实际注册,因为'cordova.js'在应用程序构建/打包之前不可用。然而,我想知道如何让Typescript识别键盘确实存在于cordova.plugins上的类型defs。否则,如何在转换过程中避免此错误?
1 个解决方案
#1
11
When installing typescript definitions, I did not install cordova-ionic
. The "standard" cordova Keyboard plugin is distinct from the cordova-ionic Keyboard plugin.
安装打字稿定义时,我没有安装cordova-ionic。 “标准”cordova键盘插件与cordova-ionic键盘插件截然不同。
tsd install cordova-ionic --save
fixed the issue.
tsd install cordova-ionic --save修复了这个问题。
Whoops.
#1
11
When installing typescript definitions, I did not install cordova-ionic
. The "standard" cordova Keyboard plugin is distinct from the cordova-ionic Keyboard plugin.
安装打字稿定义时,我没有安装cordova-ionic。 “标准”cordova键盘插件与cordova-ionic键盘插件截然不同。
tsd install cordova-ionic --save
fixed the issue.
tsd install cordova-ionic --save修复了这个问题。
Whoops.