gpt4 book ai didi

javascript - 内部版本 :Argument of type 'string | 1' is not assignable to parameter of type 'string'

转载 作者:行者123 更新时间:2023-11-28 04:47:30 34 4
gpt4 key购买 nike

我有这个 typescript 代码:

categoryColumnWide: number = 0;

this.categoryColumnWide = parseInt(storage.getItem('categoryColumnWide') || 1);

给我以下错误:

Severity Code Description Project File Line Suppression State Error Build:Argument of type 'string | 1' is not assignable to parameter of type 'string'.

有人可以帮我解决这个问题吗?我刚刚升级到新版本的 Typescript,此消息现在出现在多个地方。当我将鼠标悬停在 CategoryColumnWide 上时,它说它是一个“数字”

仅供引用,据我所知,我正在使用 Typescript 2.1

最佳答案

parseInt 需要字符串参数

您的代码通过 storage.getItem('categoryColumnWide') (字符串)或 1 (数字)

尝试将 1 作为字符串传递

this.categoryColumnWide = parseInt(storage.getItem('categoryColumnWide') || '1');

关于javascript - 内部版本 :Argument of type 'string | 1' is not assignable to parameter of type 'string' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43229140/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com