类型“typeof File”离子打字稿上不存在属性“moveFile”
Posted
技术标签:
【中文标题】类型“typeof File”离子打字稿上不存在属性“moveFile”【英文标题】:Property 'moveFile' does not exist on type 'typeof File' ionic typescript 【发布时间】:2017-09-29 12:29:38 【问题描述】:不确定出了什么问题,但是当我尝试使用来自 @ionic-native 的文件时,我收到错误消息“'typeof File' 类型上不存在属性 'moveFile'”。包子是在cmets中询问后添加的
import NavController from 'ionic-angular';
import ToastController from 'ionic-angular';
import File from '@ionic-native/file';
import Diagnostic from '@ionic-native/Diagnostic';
import CameraPreview from 'ionic-native'
import CameraPreviewOptions, CameraPreviewDimensions from '@ionic-native/camera-preview';
declare var cordova: any;
constructor(public navCtrl: NavController, public toastCtrl: ToastController)
// this.checkPermissions();
fileName = fileName.split("/").pop();
File.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ =>
this.toastCtrl.create(
package.json 应 cmets 的要求
"name": "ionic-hello-world",
"version": "0.0.0",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts":
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
,
"dependencies":
"@angular/common": "4.0.2",
"@angular/compiler": "4.0.2",
"@angular/compiler-cli": "4.0.2",
"@angular/core": "4.0.2",
"@angular/forms": "4.0.2",
"@angular/http": "4.0.2",
"@angular/platform-browser": "4.0.2",
"@angular/platform-browser-dynamic": "4.0.2",
"@ionic-native/camera": "^3.6.0",
"@ionic-native/camera-preview": "^3.6.0",
"@ionic-native/core": "^3.6.1",
"@ionic-native/diagnostic": "^3.6.1",
"@ionic-native/file": "^3.6.1",
"@ionic-native/splash-screen": "3.4.2",
"@ionic-native/status-bar": "3.4.2",
"@ionic/storage": "2.0.1",
"ionic-angular": "3.1.1",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.4.0",
"zone.js": "^0.8.5"
,
"devDependencies":
"@ionic/app-scripts": "1.3.6",
"typescript": "~2.2.1"
,
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
"platform": "ios",
"version": "",
"locator": "ios"
],
"description": "camera-app: An Ionic project"
【问题讨论】:
显示构造函数代码 【参考方案1】:您正在使用ionic-native 3.x
。
您需要在构造函数中注入File
并使用该对象。 ionic-native 2.x
中存在类中的静态函数。
constructor(public navCtrl: NavController, public toastCtrl: ToastController,
public file:File)
// this.checkPermissions();
fileName = fileName.split("/").pop();
this.file.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ =>
this.toastCtrl.create(
您还需要在 app.module.ts 中将File
设置为提供程序。
@NgModule(
//..
providers: [..,File,..]
)
【讨论】:
这适用于代码编辑器,但是当我尝试执行离子服务时,我收到:“”无法解析 ([object OBJECT]),[?]" 的所有参数 这可能是其他问题..它在同一行吗?科尔多瓦插件也不适用于ionic serve
使用模拟器/设备
你是否在 ngModule 中将 File 设置为提供者?
是的,我试过了,但在离子服务后仍然出现同样的错误
在模拟器/设备中尝试。cordova 插件在服务中不起作用以上是关于类型“typeof File”离子打字稿上不存在属性“moveFile”的主要内容,如果未能解决你的问题,请参考以下文章
是否可以仅为打字稿上的特定类型扩展 Array.prototype?
“键盘”类型上不存在打字稿错误属性“hideKeyboardAccessoryBar”。在 IONIC Moodle 应用程序上