Code Monkey home page Code Monkey logo

Comments (4)

ixahmedxi avatar ixahmedxi commented on May 18, 2024 2

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

from orbitkit.

imCorfitz avatar imCorfitz commented on May 18, 2024 1

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
    }
  }
}

from orbitkit.

ixahmedxi avatar ixahmedxi commented on May 18, 2024

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

from orbitkit.

sayandedotcom avatar sayandedotcom commented on May 18, 2024

types like next-auth types, etc .. check this. I am facing difficult to configure it

from orbitkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.