Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtual:meta-layouts shows type declaration error. #9

Closed
premdasvm opened this issue Sep 19, 2023 · 5 comments · Fixed by #10
Closed

virtual:meta-layouts shows type declaration error. #9

premdasvm opened this issue Sep 19, 2023 · 5 comments · Fixed by #10

Comments

@premdasvm
Copy link

Hi,

I'm tryna use your package with unplugin-vue-router, everything is working fine, i can see the different layouts and all. but i can't seem to get rid of the type declaration error. 🥲

Screenshot 2023-09-20 at 2 49 01 AM

here is my tsconfig.app.json

{
  "extends": ["@vue/tsconfig/tsconfig.json", "@vue/tsconfig/tsconfig.dom.json"],
  "include": [
    "env.d.ts",
    "src/**/*",
    "src/**/*.vue",
    "typed-router.d.ts",
    "auto-imports.d.ts",
    "components.d.ts"
  ],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["vite-plugin-vue-meta-layouts/client"]
  }
}

Screenshot 2023-09-20 at 2 50 49 AM

For reference Repo

@markthree
Copy link
Member

markthree commented Sep 20, 2023

@premdasvm Hi, I found out that there is a conflict between extends and compilerOptions types, commenting out extends solves the problem temporarily.

So far I haven't found a ts method that is compatible with your repo. 😭

{
  // "extends": ["@vue/tsconfig/tsconfig.json", "@vue/tsconfig/tsconfig.dom.json"],
  "include": [
    "env.d.ts",
    "src/**/*",
    "src/**/*.vue",
    "typed-router.d.ts",
    "auto-imports.d.ts",
    "components.d.ts"
  ],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["vite-plugin-vue-meta-layouts/client"]
  }
}

@premdasvm
Copy link
Author

@markthree commenting out the extends wouldn't affect anything else right?

@markthree
Copy link
Member

markthree commented Sep 20, 2023

@premdasvm I'm sorry, I'm busy with other work today, I think we can find some kind of configuration to be more compatible with this repo without having to change too many things。

A temporary ignore solution is ↓

// src/router/index.ts
import { routes as fileRoutes } from 'vue-router/auto/routes'
import { createRouter, createWebHistory } from 'vue-router'
// @ts-ignore
import { setupLayouts } from 'virtual:meta-layouts'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // @ts-ignore
  routes: setupLayouts(fileRoutes)
})

export default router
// tsconfig.app.json
{
  "extends": ["@vue/tsconfig/tsconfig.json", "@vue/tsconfig/tsconfig.dom.json"],
  "include": [
    "env.d.ts",
    "src/**/*",
    "src/**/*.vue",
    "typed-router.d.ts",
    "auto-imports.d.ts",
    "components.d.ts"
  ],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
    // "types": ["vite-plugin-vue-meta-layouts/client"]
  }
}

Please wait until I'm done with work, I'll take a hard look at this repo and try to find a better type compatibility solution! ✍️

@markthree
Copy link
Member

@premdasvm Hi,I took a closer look at the repo, and adding the following option fixes it perfectly without making too many changes.

// tsconfig.app.json
{
  "extends": ["@vue/tsconfig/tsconfig.json", "@vue/tsconfig/tsconfig.dom.json"],
  "include": [
    "env.d.ts",
    "src/**/*",
    "src/**/*.vue",
    "typed-router.d.ts",
    "auto-imports.d.ts",
    "components.d.ts"
  ],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
+   "moduleResolution": "Node",
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["vite-plugin-vue-meta-layouts/client"]
  }
}

@PWie
Copy link
Contributor

PWie commented Oct 3, 2023

The actual solution to this is to declare types entry for /client in package.json:

// package.json
{
   // ...
  "exports": {
    "./client": {
      "types": "./client.d.ts"
    },
    "./*": "./*",
    ".": {
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "types": "./dist/index.d.ts"
    }
  },
}

PWie added a commit to PWie/vite-plugin-vue-meta-layouts that referenced this issue Oct 3, 2023
markthree pushed a commit that referenced this issue Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants