nei1ee/unocss-preset-uni

vite.config.ts presetUni() 报错

Loongphy opened this issue · 1 comments

Type 'Preset<Theme>' is not assignable to type 'Preset<{}> | Preset<{}>[]'.
  Type 'Preset<Theme>' is not assignable to type 'Preset<{}>'.
    Types of property 'rules' are incompatible.
      Type 'Rule<Theme>[] | undefined' is not assignable to type 'Rule<{}>[] | undefined'.
        Type 'Rule<Theme>[]' is not assignable to type 'Rule<{}>[]'.
          Type 'Rule<Theme>' is not assignable to type 'Rule<{}>'.
            Type '[RegExp, DynamicMatcher<Theme>]' is not assignable to type 'Rule<{}>'.
              Type '[RegExp, DynamicMatcher<Theme>]' is not assignable to type '[string, CSSObject | CSSEntries]'.
                Type at position 0 in source is not compatible with type at position 0 in target.
                  Type 'RegExp' is not assignable to type 'string'.
  • vite.config.ts
import { resolve } from 'path'
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'
import Unocss from 'unocss/vite'
import { presetIcons } from 'unocss'
import { presetUni } from 'unocss-preset-uni'
import { UnoCSSToUni } from 'unocss-preset-uni/vite'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': resolve('./src'),
    },
  },
  plugins: [
    uni(),

    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      // global imports to register
      imports: [
        'vue',
        'uni-app',
        'pinia',
      ],
      dts: 'src/auto-imports.d.ts',
    }),

    // https://github.com/unocss/unocss
    Unocss({
      presets: [
        presetUni(),
        presetIcons(),
      ],
    }),
    // https://github.com/zguolee/unocss-preset-uni
    // Make sure it's behind Unocss()
    UnoCSSToUni(),
  ],
})

我也不知道为什么会报类型错误😂(和@unocss/preset-uno代码一样),目前的解决办法

import type { Preset } from 'unocss'
...
UnoCSS({
  presets: [
    presetUni() as Preset,
    presetIcons(),
  ],
}),

如果有解决办法👏欢迎PR