unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.29k stars 198 forks source link

Not working properly when using ternary operator #279

Closed threedayAAAAA closed 2 years ago

threedayAAAAA commented 2 years ago

Describe the bug

Not working properly when using ternary operator

Reproduction

Not working properly when using ternary operator

{
    vueTemplate: true,
    imports: [
      'vue',
      'vue-router',
      {
        '@sxf/util/uuid': ['uuid'],
      },
    ],
    eslintrc: {
      enabled: true,
      filepath: './.eslintrc-auto-import.json',
      globalsPropValue: true,
    },
    dirs: [
      './util/**',
    ],
    dts: '../../types/auto-imports.d.ts',
  }
// util/config.ts
export const data = 1
// main.ts
const a = Math.random() > 0.5 ? data : 2

System Info

"unplugin-auto-import": "^0.11.2",

Used Package Manager

pnpm

Validations

azaleta commented 2 years ago

It works fine. Does you config.ts is in src/util? Pls check your auto-imports.d.ts if the data has been check->imported

 dirs: [
   './src/composables',
   './src/util',
 ],

image image image

threedayAAAAA commented 2 years ago

It works fine. Does you config.ts is in src/util? Pls check your auto-imports.d.ts if the data has been check->imported

 dirs: [
   './src/composables',
   './src/util',
 ],

image image image

You can check the reproduction link

https://codesandbox.io/s/elastic-bose-ok23h3?file=/src/main.ts

image

azaleta commented 2 years ago

Please add auto-imports.d.ts to your tsconfig image

image image

threedayAAAAA commented 2 years ago

Please add auto-imports.d.ts to your tsconfig image

image image

Seems like I'm providing a wrong use case. An error is reported when the ternary operator gets the value of auto-import. For example the picture below

image

image