Skip to content

Type error when passing presets from unocss to unocss/vite #5050

Description

@hi-ogawa

UnoCSS version

66.5.12

Describe the bug

I came accross the type error on vitest-dev/vitest#9192 and it appears there is inherent duplicate or inconsistent types within unocss package.

import { presetMini } from 'unocss';
import Unocss from 'unocss/vite';

Unocss({
  presets: [presetMini()],
});
❯ tsc -b
repro.ts:5:13 - error TS2322: Type 'Preset<Theme$1>' is not assignable to type 'PresetOrFactoryAwaitable<Theme$1> | PresetOrFactoryAwaitable<Theme$1>[]'.
  Type 'import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Pn<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>' is not assignable to type 'Preset<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>'.
    Types of property 'rules' are incompatible.
      Type 'import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Gn<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>[] | undefined' is not assignable to type 'Rule<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>[] | undefined'.
        Type 'import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Gn<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>[]' is not assignable to type 'Rule<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>[]'.
          Type 'import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Gn<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>' is not assignable to type 'Rule<import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").xt>'.
            Type 'StaticRule' is not assignable to type 'Rule<Theme$1>'.
              Type '[string, CSSObject | CSSEntries | (string | CSSValueInput)[], (RuleMeta | undefined)?]' is not assignable to type 'StaticRule'.
                Type at position 1 in source is not compatible with type at position 1 in target.
                  Type 'import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Qt | import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").Yt | (string | import("/home/projects/vitejs-vite-hhrsjwej/node_modules/unocss/dist/index-XUBLdNw_").tn)[]' is not assignable to type 'CSSObject | CSSEntries | (string | CSSValueInput)[]'.
                    Type '(string | CSSValueInput)[]' is not assignable to type 'CSSObject | CSSEntries | (string | CSSValueInput)[]'.
                      Type '(string | CSSValueInput)[]' is not assignable to type 'CSSEntries'.
                        Type 'string | CSSValueInput' is not assignable to type 'CSSEntry'.
                          Type 'string' is not assignable to type '[string, string | number | undefined, (Arrayable<string> | undefined)?]'.

5   presets: [presetMini()],
              ~~~~~~~~~~~~


Found 1 error.

Reproduction

https://stackblitz.com/edit/vitejs-vite-hhrsjwej?file=repro.ts

System Info

stackblitz

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions