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

create a packages/types folder for all d.ts files #23

Closed
sayandedotcom opened this issue Apr 6, 2024 · 4 comments
Closed

create a packages/types folder for all d.ts files #23

sayandedotcom opened this issue Apr 6, 2024 · 4 comments

Comments

@sayandedotcom
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@ixahmedxi
Copy link
Owner

Why would you want to declare your own types and share it across the monorepo?

@sayandedotcom
Copy link
Author

@ixahmedxi
Copy link
Owner

Typically you can avoid such scenarios by just putting these declarations where they are used and typescript would just pick it up when the file is imported, see here for example: https://github.com/ixahmedxi/orbitkit/blob/main/packages/auth/src/lucia.ts

@imCorfitz
Copy link
Contributor

By creating a dedicated types package, you imply that you want to share the same types across all apps and packages. Conceptually that wouldn't be the best practice as you likely use packages differently in different apps. Take a package like Auth.js which relies on a types declaration file (e.g. next-auth.d.ts) in order to make the user or session object type safe. If you use Auth.js on both your admin dashboard app and your front-end app, you may not need to share the same properties in the user object for both apps.

For example, in your front-end app, you might want to include an avatar picture and points collected and in your admin dashboard a scope of privileges for what a user can access.

That means that for your front-end app, your declaration file should look like this:

declare module "next-auth" {
  interface User {
    avatar: string
    points: number
  }
}

whereas in your admin dashboard app, it should look like this:

declare module "next-auth" {
  interface User {
    privileges: {
      read: boolean
      write: boolean
    }
  }
}

@ixahmedxi ixahmedxi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2024
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

No branches or pull requests

3 participants