[vue插件]ts版本问题合集

在使用ts进行代码开发的化,首先要注意以下几点:

使用的包添加ts支持

例如mockjs添加 @types/mockjs支持(如果存在)

或者在shims-vue.d.ts添加声明

类型检查报错

Parameter ‘b’ implicitly has an ‘any’ type

在.eslinttrc.js文件中添加配置很多都无效

Argument ‘callback’ should be typed (@typescript-eslint/explicit-module-boundary-types) at

tsconfig.json中"strict": false,

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

使用了require方法

warning: Missing return type on function

添加返回或者设置为void

warning: Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)

“@typescript-eslint/no-explicit-any”:“off”

error: ‘text’ is defined but never used (vue/no-unused-vars)

‘@typescript-eslint/no-unused-vars’: “off”,
‘vue/no-unused-vars’: “off”,
‘no-unused-vars’: “off”,
都无效

‘v-show’ directives cannot be put on tags

v-show调整到具体的dom上

Don’t use object as a type. The object type is currently hard to use

类型暂时改为any

error: The array literal notation [] is preferable (@typescript-eslint/no-array-constructor)

error: Don’t use Function as a type. The Function type accepts any function-like value. It provides no type safety when calling the function, which can be a common source of bugs. It also accepts things like class declarations, which will throw at runtime as they will not be called with new. If you are expecting the function to accept certain arguments, you should explicitly define the function shape (@typescript-eslint/ban-types)

error: Type RegExp trivially inferred from a RegExp literal, remove type annotation

error: Irregular whitespace not allowed

“no-irregular-whitespace”: “off”,

它就是由不规则空格引起的,解决办法就是要格式化文档。

You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.

chainWebpack(config) {
        config.resolve.alias.set(‘vue-i18n’,‘vue-i18n/dist/vue-i18n.cjs.js’)
}

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

vue.config.js 设置
client:{
            overlay:false
 },

TS2698: Spread types may only be created from object types

Object.assign(target,source)

TS2769: No overload matches this call.

export declare function createI18n
<Legacy extends boolean = true, 
Options extends I18nOptions = I18nOptions,
Messages = Options[‘messages’] extends object ? Options[‘messages’] : {}, 
DateTimeFormats = Options[‘datetimeFormats’] extends object ? Options[‘datetimeFormats’] : {}, 
NumberFormats = Options[‘numberFormats’] extends object ? Options[‘numberFormats’] : {}, 
OptionLocale = Options[‘locale’] extends string ? Options[‘locale’] : Locale>
(options: Options, LegacyVueI18n?: any): I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, Legacy>;

Logo

前往低代码交流专区

更多推荐