nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
961 stars 59 forks source link

nuxt/icon breaks nuxt's plugin system types #214

Closed OrlS15 closed 4 months ago

OrlS15 commented 4 months ago

If you create a plugin and provide some functions, these functions are not typed if nuxt/icon is installed.

 // ~/plugins/test.ts
export default defineNuxtPlugin(async () => {
  return {
    provide: {
      aaa: () => 'WEWE',
    },
  };
});
 // ~/app.vue
<script setup lang="ts">
useNuxtApp().$aaa(); // $aaa is unknown
</script>

<template></template>

In ~/.nuxt/types/plugins.d.ts NuxtAppInjections is any (because one of the unions is any):

type NuxtAppInjections = 
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/navigation-repaint.client").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/check-outdated-build.client").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/revive-payload.server").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/revive-payload.client").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/chunk-reload.client").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/head/runtime/plugins/unhead").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/router").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/@nuxt+devtools@1.3.9_rollup@4.19.0_vite@5.3.4_@types+node@20.14.11_terser@5.31.3_/node_modules/@nuxt/devtools/dist/runtime/plugins/devtools.server").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/@nuxt+devtools@1.3.9_rollup@4.19.0_vite@5.3.4_@types+node@20.14.11_terser@5.31.3_/node_modules/@nuxt/devtools/dist/runtime/plugins/devtools.client").default> &
  // this one below is any
  InjectionType<typeof import("../../node_modules/.pnpm/@nuxt+icon@1.3.0_magicast@0.3.4_rollup@4.19.0_vite@5.3.4_@types+node@20.14.11_terser@5.31.3__vue@3.4.33/node_modules/@nuxt/icon/dist/runtime/plugin").default /* <-- 'default' is any */> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/dev-server-logs").default> &
  InjectionType<typeof import("../../node_modules/.pnpm/nuxt@3.12.4_@parcel+watcher@2.4.1_@types+node@20.14.11_ioredis@5.4.1_magicast@0.3.4_rollup@4._lljhbfrgkudpe6zumtjkp3yzvi/node_modules/nuxt/dist/app/plugins/check-if-layout-used").default> &
  InjectionType<typeof import("../../plugins/test").default>

The file node_modules/@nuxt/icon/dist/runtime/plugin.d.ts is empty.

Reproduction: https://stackblitz.com/edit/github-upzndu?file=plugins%2Ftest.ts,app.vue (stackblitz's types don't work in .vue files, test it in local)