关于在vue3 reactive 中使用TypeScript时,出现’state’ implicitly has type ‘any’ because it does not have a type annotation and is referenced directly or indirectly in its own initializer.报错。

关于这个错误的解释是:

state ”隐式具有类型“ any ”,因为它 没有类型注释 并且在其自己的初始化程序中直接或间接引用

出现这个问题时由于 TypeScript 里自带的类型检测,导致 编译报错 ,但实际并不影响程序是使用,毕竟他在 js 中是完全可行的。
在这里插入图片描述
这个 解决方法 是用了TypeScript中的 类型断言 ,通过 类型断言 这种方式可以告诉编译器, “相信我,我知道自己在干什么” 类型断言 好比其它语言里的 类型转换 ,但是 不进行特殊的数据检查和解构 。 它没有运行时的影响,只是在编译阶段起作用。 TypeScript 会假设你,程序员,已经进行了必须的检查。
简言之 ,你(编译器)别问我(程序)了,我知道自己在干什么。

it does not have a type annotation and is referenced directly or indirectly in its own initializer 关于在vue3 reactive中使用TypeScript时,出现'state' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.报错。关于这个错误的解释是:“state”隐式具有类型“any”,因为它没有类型注释,并且在其自己的初始化程序中直接或间接引用。解决方案出现这个问题时由 在上述代码中,使用this报错:'this' implicit ly has type 'any' because it does not have a type annotation . function处报错:An outer value of 'this' is shadowed by t... 'url' implicit ly has return type 'any' because it does not have a return type annotation and is reference d di rect ly or ind i rect ly in one of its return e xpressions. 错误信息: Element implicit ly has an ‘any’ type because expression of type ‘string’ can’t be used to ind ex type ‘{ name: string; age: number; }’. No ind ex signature with a parameter of type ‘s...
元素隐式具有 “any” 类型,因为类型为 “string” 的表达式不能用于索引类型 在使用 typescript 时,在对变量进行了类型声明后,在使用for in 的时候出现了这样的问题 经过查资料,key值的类型不是string,在javascript中是默认给你转好的,而在 Typescript 中则不是,因此要么转,要么声明,要么忽略 修改tsconfig.json文件中的配置 export function isValidKey(key: string | number | sym
code 类型 英文描述 中文描述 1002 错误 Unterminated string literal. 未终止的字符串文本。 1003 错误 Identifier expected. 应为标识符。 1005 错误 '{0}' expected. 应为“{0}”。 1006 错误 A file cannot have a reference to itself. 文件不能引用自身。 1009...