首页 > 其他分享 >OpenHarmony升級4.0后,编译报错。

OpenHarmony升級4.0后,编译报错。

时间:2024-03-15 17:57:12浏览次数:21  
标签:OpenHarmony bundleName string 升級 let key ERROR 报错 type

1、 Use explicit types instead of "any", "unknown" (arkts-no-any-unknown)

报错信息:

ERROR: ArkTS:ERROR File: .../WeatherRow.ets:99:12
 Use explicit types instead of "any", "unknown" (arkts-no-any-unknown)

错误代码:

  ForEach(this.weatherCityList, (item: string) => {
          ...
        }, item => item)

修改代码:

  ForEach(this.weatherCityList, (item: string) => {
          ...
        }, (item:string) => item)

错误代码:

  this.screenModeModel.getDisplayOffTimeValue().then(index=>{
      this.AnimationText=this.checked=this.AnimationMultiplier[index as number]
    })

修改代码:

 this.screenModeModel.getDisplayOffTimeValue().then((index:number)=>{
      this.AnimationText=this.checked=this.AnimationMultiplier[index]
    })

错误代码:

  private AnimationMultiplier;

修改代码:

private AnimationMultiplier: Resource[] = [$r('app.string.seconds', 30), $r('app.string.seconds', 60), $r('app.string.minutes',5), $r('app.string.never')];

错误代码:

   private appItem: any

修改代码:


2、Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)

报错信息:

ERROR: ArkTS:ERROR File: ...AppData.ets:19:27
 Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)

错误代码:

export function appInit(): Array<AppInfo> {
   let appInfo = [
    { bundleName: 'com.example.myapplication', name: 'myapplication', icon: $r('app.media.icon') },
    { bundleName: 'com.example.distributedcalc', name: '计算器', icon: $r('app.media.calculator') }
   ]
  return appInfo
}

修改代码:

export function appInit(): Array<AppInfo> {
  let appInfo = [
    new AppInfo('com.example.myapplication', 'myapplication', $r('app.media.icon')),
    new AppInfo('com.example.distributedcalc', '计算器', $r('app.media.calculator'))
  ]
  return appInfo
}

3、 Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

报错信息:

ERROR: ArkTS:ERROR File: ...Util.ets:100:33
 Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

错误代码:

    /**
     * The bundle name of the application.
     *
     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
     * @systemapi Hide this for inner system use.
     * @since 9
     */
    bundleName?: string;
   ...
   let appTime = new AppTime(res[key].bundleName, res[key].abilityPrevAccessTime, res[key].abilityInFgTotalTime)

修改代码:

    let appTime = new AppTime(res[key].bundleName!, res[key].abilityPrevAccessTime!, res[key].abilityInFgTotalTime!)

4、 Type 'AppTime[]' is not assignable to type 'never[]'.

报错信息:

ERROR: ArkTS:ERROR File: ...Util.ets:110:3
 Type 'AppTime[]' is not assignable to type 'never[]'.
  Type 'AppTime' is not assignable to type 'never'.

错误代码:

   let statisticals = []
   let list: Array<AppTime> = []
   statisticals = list

修改代码:

   let statisticals: Array<AppTime> = []
   let list: Array<AppTime> = []
   statisticals = list

5、 Argument of type 'string' is not assignable to parameter of type 'never'.

报错信息:

ERROR: ArkTS:ERROR File: ...Util.ets:113:20
 Argument of type 'string' is not assignable to parameter of type 'never'.

错误代码:

  let panelName = []
  ...
  export default class AppTime {
    bundleName: string //应用的包名
  ...
  panelName.push(getAppName(statisticals[i].bundleName))

修改代码:

   let panelName:Array<string>  = []
    ...
    export default class AppTime {
      bundleName: string //应用的包名
    ...
    panelName.push(getAppName(statisticals[i].bundleName))

6、"for .. in" is not supported (arkts-no-for-in)

报错信息:

ERROR: ArkTS:ERROR File: ...Util.ets:97:3
 "for .. in" is not supported (arkts-no-for-in)

错误代码:

  let res:usageStatistics.BundleStatsMap = await usageStatistics.queryBundleStatsInfos(0, 20000000000000)
  for (let key in res) {
  }

修改代码:

  let bundleName:string
  let abilityPrevAccessTime:number
  let abilityInFgTotalTime:number
  JSON.parse(JSON.stringify(res).toString(),(key:string, value:myBundleStatsInfo) =>{
    if (key==="bundleName") {
      bundleName=value as string
    }
    if (key==="abilityPrevAccessTime") {
      abilityPrevAccessTime=value  as number
    }

    if (key==="abilityInFgTotalTime") {
      abilityInFgTotalTime=value  as number
    }
    if (key===bundleName) {
      console.error('bundleName=' + bundleName+"abilityPrevAccessTime="+abilityPrevAccessTime);
      let appTime = new AppTime(bundleName!,abilityPrevAccessTime!,abilityInFgTotalTime!)
      list.push(appTime)
    }
  });

6、Indexed access is not supported for fields (arkts-no-props-by-index)

报错信息:

ERROR: ArkTS:ERROR File: ...WeatherUtil.ets:61:31
 Indexed access is not supported for fields (arkts-no-props-by-index)

错误代码:

 resultTemp = JSON.stringify(resultObject["data"]["weather"])

修改代码:


7、Use arrow functions instead of function expressions (arkts-no-func-expressions)

报错信息:

ERROR: ArkTS:ERROR File: screenAndBrightness.ets:126:50
 Use arrow functions instead of function expressions (arkts-no-func-expressions)

错误代码:

JSON.parse(JSON.stringify(res).toString(), function (key:string, value:myBundleStatsInfo) {
        console.log('dhf_ key=' + key);
        console.log('dhf_ value=' + value);
      });

修改代码:

   JSON.parse(JSON.stringify(res).toString(),(key:string, value:myBundleStatsInfo) =>{
        console.log('dhf_ key=' + key);
        console.log('dhf_ value=' + value);
      });

8、Property 'extraData' has no initializer and is not definitely assigned in the constructor.

报错信息:

ERROR: ArkTS:ERROR File: HttpRequestOptions.ets:22:3
 Property 'extraData' has no initializer and is not definitely assigned in the constructor.

错误代码:

import Logger from './Logger'

const TAG = '[HttpRequestOptions]'

export class HttpRequestOptions {
  method: string
  extraData: Object
  header: Object
  readTimeout: number
  connectTimeout: number

  constructor() {
    this.method = 'GET'
    this.header = {
      'Content-Type': 'application/json'
    }
    this.readTimeout = 5000
    this.connectTimeout = 5000
  }

  setMethod(method: string) {
    this.method = method
    Logger.info(TAG, `setMethod method is ${this.method}`)
  }

  setExtraData(extraData: Object) {
    this.extraData = extraData
    Logger.info(TAG, `setExtraData extraData is ${JSON.stringify(this.extraData)}`)
  }

  setHeader(header: Object) {
    this.header = header
    Logger.info(TAG, `setHeader header is ${JSON.stringify(this.header)}`)
  }
}

export default new HttpRequestOptions()

修改代码:


9、Type 'null' is not assignable to type 'Object'.

报错信息:

ERROR: ArkTS:ERROR File: HttpRequestOptions.ets:22:3
 Type 'null' is not assignable to type 'Object'.

错误代码:

  extraData: Object =null

修改代码:

 extraData: Object =""

10、 Type 'undefined' is not assignable to type 'HttpResponse'.

报错信息:

  ERROR: ArkTS:ERROR File: WeatherUtil.ets:11:5
  Type 'undefined' is not assignable to type 'HttpResponse'.

错误代码:


 let requestData: http.HttpResponse = undefined

修改代码:

  let requestData: http.HttpResponse

标签:OpenHarmony,bundleName,string,升級,let,key,ERROR,报错,type
From: https://www.cnblogs.com/donghaifeng-2016/p/17849908.html

相关文章

  • 连接MySQL报错,is not allowed to connect to this MySQL server
    问题描述:        本机装的MySQL数据库,本机可以正常连接,其他机器访问报错,isnotallowedtoconnecttothisMySQLserver,防火墙等其他策略均配置没问题。  解决方案:    出现该问题的原因是,MySQL数据库只允许自身所在的本机器连接,不允许远程连接。1、......
  • Linux - 报错“Address already in use”解决方案
    报"Addressalreadyinuse",如下图所示:错误原因:某程序正在使用端口。(这里我使用的是端口“8888”)可以通过命令查看所有正在使用的端口:netstat-tunllp 解决方案1.找到占用该端口的进程号使用命令:sudonetstat-anp|grep"8888"(端口号)可以看到进程号为8888的serv......
  • SSH登录失败报错Permission denied (publickey)的解决方法
    SSH(SecureShell)是一种加密的网络协议,用于在网络上安全地传输数据。它被广泛用于远程登录和执行命令。然而,有时候当我们尝试使用SSH登录时,可能会遇到错误消息Permissiondenied(publickey)导致登录失败。这种情况可能由多种原因引起。在本文中,我们将探讨导致SSH登录失败的......
  • 【已解决】报错 NVIDIA-SMI has failed because it couldn‘t communicate with the N
    在重装系统ubuntu20.4.6之后,运行程序的时候无法启动nvidia显卡,然后输入nvidia-smi报错hasfailedbecauseitcouldn‘tcommunicatewiththeNVIDIAdriver,在网上查看许多解决方案也没有解决,其中这篇文章(https://www.zhihu.com/question/474222642)写的较为详细,但是我试过依旧无......
  • 【rust】《处理报错Cannot find a libtorch install, you can either:》
    在学习rust的tch-rs框架的时候,引入依赖并运行小demo的时候报错了;错误信息如下:报错信息Cannotfindalibtorchinstall,youcaneither:-InstalllibtorchmanuallyandsettheLIBTORCHenvironmentvariabletoappropriatepath.-Useasystemwideinstallin/us......
  • jumserver-master版本 lina组件启动报错
    node-vv16.15.1 npm-v8.11.0yarn-v1.22.22 yarnserveyarnrunv1.22.22$vue-cli-serviceserveINFOStartingdevelopmentserver...10%building2/2modules0activeERRORSyntaxError:Cannotuseimportstatementoutsideamodule/opt/lina-ma......
  • 【rust】《处理报错could not execute `llvm-config` one or more times》
    报错信息couldnotexecute`llvm-config`oneormoretimes,iftheLLVM_CONFIG_PATHenvironmentvariableissettoafullpathtovalid`llvm-config`executableitwillbeusedtotrytofindaninstanceof`libclang`onyoursystem:"couldn'texec......
  • 【Anaconda环境报错】‘activate.bat‘ 不是内部或外部命令,也不是可运行的程序 或批处
    在使用Anaconda进行Python开发时,我们经常需要激活Anaconda环境来确保我们的代码在正确的环境中运行。然而,有时我们可能会遇到"‘activate.bat’不是内部或外部命令,也不是可运行的程序或批处理文件"的错误提示,这会导致我们无法成功激活所需的环境。本文将介绍一些可能的解决......
  • mybatis plus saveBatch报错问题
    sessionRecordHumanService.saveBatch(dataList);具体报错如下:org.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.exceptions.PersistenceException: ###Errorupdatingdatabase.Cause:java.lang.IllegalArgumentException:MappedSta......
  • React报错:Uncaught Error: Too many re-renders. React limits the number of renders
    UncaughtError:Toomanyre-renders.Reactlimitsthenumberofrenderstopreventaninfiniteloop.atrenderWithHooks(react-dom.development.js:16317:1)atmountIndeterminateComponent(react-dom.development.js:20074:1)atbeginWork(react-do......