HWww
HWww
  • 发布:2024-07-09 11:18
  • 更新:2024-07-19 11:52
  • 阅读:180

uts 编译类型检测bug

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 记不到了

HBuilderX类型: 正式

HBuilderX版本号: 4.23

手机系统: Android

手机系统版本号: Android 14

手机厂商: 华为

手机机型: 记不到了

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

没有

预期结果:

没有

实际结果:

没有

bug描述:

uts 开发安卓app编译问题,谁告诉我怎么写
1、定义了一个hooks 用于获取系统信息
用的时候报这个错,我写过ts 你这个不是bug吗

2024-07-09 11:18 负责人:DCloud_Android_DQQ 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

提供一下可以复现问题的示例

  • HWww (作者)

    type windowInfo = {

    height : String,

    top : String

    }


    const useGetWindowInfo = () : windowInfo => {

    const windowInfo : windowInfo = {

    height: "0px",

    top: "0px"

    }

    //#ifdef MP-WEIXIN

    const { top, height } = uni.getMenuButtonBoundingClientRect();

    windowInfo.height = height + "px";

    windowInfo.top = top + "px";

    //#endif

    //#ifndef MP-WEIXIN

    const info = uni.getWindowInfo();

    windowInfo.height = "50px";

    windowInfo.top = info.statusBarHeight + "px";

    //#endif


    return windowInfo   

    }


    export default useGetWindowInfo

    2024-07-09 17:15

  • HWww (作者)

    以下是一个hooks 获取系统信息

    const useGetWindowInfo = () : any => {

    const top = ref<String>("0px");

    const height = ref<String>("0px");

    //#ifdef MP-WEIXIN

    const { top, height } = uni.getMenuButtonBoundingClientRect();

    height.value = height + "px";

    top.value = top + "px";

    //#endif

    //#ifndef MP-WEIXIN

    const info = uni.getWindowInfo();

    height.value = "50px";

    top.value = info.statusBarHeight + "px";

    //#endif

    return {

    height,

    top

    }

    }

    export default useGetWindowInfo


    以下是用这个hooks


    <template>

    <view class="index">

    <view class="index-navigation" :style="{

    height:height,

    top:top

    }">

    </view>


    </view>  

    </template>


    <script lang="uts" setup>

    import useGetWindowInfo from "../../hooks/useGetWindowInfo.uts"

    const navigationTop = ref<String>("0px");

    const navigationHeight = ref<String>("0px");

    const { height, top } = useGetWindowInfo()

    onMounted(() => {

    // const { height, top } = useGetWindowInfo();

    // navigationTop.value = top;

    // navigationHeight.value = height;

    // console.log(process.env.NODE_ENV);


    })  

    </script>


    <style lang="scss" scoped>

    .index {

    width: 100%;

    background-color: rgba(245, 245, 245, 1);

    position: relative;

    min-height: 800rpx;


        &-navigation {  
    background-color: red;
    position: absolute;
    width: 100%;
    }
    }

    </style>


    报错


    17:21:38.430 ‌error: Not enough information to infer type variable B‌

    17:21:38.430 at pages/index/index.uvue:3:41

    17:21:38.430 1 | <template>

    17:21:38.430 2 | <view class="index">

    17:21:38.430 3 | <view class="index-navigation" :style="{

    17:21:38.430 | ^

    17:21:38.430 4 | height:height,

    17:21:38.430 5 | top:top

    17:21:38.430 ‌error: Not enough information to infer type variable T‌

    17:21:38.430 at pages/index/index.uvue:3:41

    17:21:38.430 1 | <template>

    17:21:38.430 2 | <view class="index">

    17:21:38.430 3 | <view class="index-navigation" :style="{

    17:21:38.430 | ^

    17:21:38.430 4 | height:height,

    17:21:38.430 5 | top:top

    2024-07-09 17:24

  • HWww (作者)

    发给你两个回复都会出现bug,第一个bug详情忘了发给你了是这样的

    17:25:30.495 ‌error: Variable expected‌

    17:25:30.495 at hooks/useGetWindowInfo.uts:18:12

    17:25:30.495 16 |

    17:25:30.495 17 | const info = uni.getWindowInfo();

    17:25:30.495 18 | windowInfo.height = "50px";

    17:25:30.495 | ^

    17:25:30.495 19 | windowInfo.top = info.statusBarHeight + "px";

    17:25:30.495 20 |

    17:25:30.495 ‌error: Variable expected‌

    17:25:30.496 at hooks/useGetWindowInfo.uts:19:12

    17:25:30.496 17 | const info = uni.getWindowInfo();

    17:25:30.496 18 | windowInfo.height = "50px";

    17:25:30.496 19 | windowInfo.top = info.statusBarHeight + "px";

    2024-07-09 17:26

  • HWww (作者)

    这样写也有问题,你们确定这是ts?各种ts写法都尝试过了

    type windowInfo = {

    height : String,

    top : String

    }


    const useGetWindowInfo = () : windowInfo => {

    let statusBarHeight : String;

    let statusBarTop : String;

    //#ifdef MP-WEIXIN

    const { top, height } = uni.getMenuButtonBoundingClientRect();

    statusBarHeight = height + "px";

    statusBarTop = top + "px";

    //#endif

    //#ifndef MP-WEIXIN

    const info = uni.getWindowInfo();

    statusBarHeight = "50px";

    statusBarTop = info.statusBarHeight + "px";

    //#endif


    return {  
    height: statusBarHeight,
    top: statusBarTop
    } as windowInfo

    }


    export default useGetWindowInfo


    以下是用这个hooks的代码

    <template>

    <view class="index">

    <view class="index-navigation" :style="{

    height:navigationHeight,

    top:navigationTop

    }">

    </view>


    </view>  

    </template>


    <script lang="uts" setup>

    import useGetWindowInfo from "../../hooks/useGetWindowInfo.uts"

    const navigationTop = ref<String>("0px");

    const navigationHeight = ref<String>("0px");

    onMounted(() => {

    const { height, top } = useGetWindowInfo();

    navigationTop.value = top;

    navigationHeight.value = height;


    })  

    </script>


    <style lang="scss" scoped>

    .index {

    width: 100%;

    background-color: rgba(245, 245, 245, 1);

    position: relative;

    min-height: 800rpx;


        &-navigation {  
    background-color: red;
    position: absolute;
    width: 100%;
    }
    }

    </style>


    以下是报错

    17:33:35.510 ‌error: Cannot access class 'uni.UNIFB0641F.windowInfo'. Check your module classpath for missing or conflicting dependencies‌

    17:33:35.510 at pages/index/index.uvue:17:26

    17:33:35.510 15 | const navigationHeight = ref<String>("0px");

    17:33:35.510 16 | onMounted(() => {

    17:33:35.510 17 | const { height, top } = useGetWindowInfo();

    17:33:35.510 | ^

    17:33:35.510 18 | navigationTop.value = top;

    17:33:35.510 19 | navigationHeight.value = height;

    17:33:35.510 ‌error: Unresolved reference: top‌

    17:33:35.510 at pages/index/index.uvue:17:18

    17:33:35.510 15 | const navigationHeight = ref<String>("0px");

    17:33:35.510 16 | onMounted(() => {

    17:33:35.510 17 | const { height, top } = useGetWindowInfo();

    17:33:35.510 | ^

    17:33:35.510 18 | navigationTop.value = top;

    17:33:35.510 19 | navigationHeight.value = height;

    2024-07-09 17:35

DCloud_Android_DQQ

DCloud_Android_DQQ

可以复现问题的示例。打个压缩包发给我吧。。

  • HWww (作者)

    我代码都发给你了,你随便找个项目,复制我发给你的hook useGetWindowInfo 就是这个,随便在哪里用就看的出来了,发了三个不同的写法给你,都是类型检测错误,麻烦你看哈

    2024-07-10 11:01

  • DCloud_Android_DQQ

    回复 HWww: 发我一个可以复现问题的可运行示例。这样也方便更快速的定位您的问题

    2024-07-10 11:52

  • HWww (作者)

    回复 DCloud_Android_DQQ: 发给你了啊,咋个不回复

    2024-07-17 17:47

HWww

HWww (作者)

这个,你可以多试试,把我上面给你的代码看看

DCloud_Android_DQQ

DCloud_Android_DQQ

你上次的附件我使用最新的alpha 可以正常编译。 没有复现问题

要回复问题请先登录注册