1

I have a project https://github.com/theADAMJR/2PG and https://github.com/theADAMJR/2PG-Dashboard and I keep having to copy and paste types between both projects.

export class AutoModModule extends Module {
    ignoredRoles: string[] = [];
    autoDeleteMessages = true;
    filters: MessageFilter[] = [];
    banWords: string[] = [];
    banLinks: string[] = [];
    filterThreshold = 5;
    autoWarnUsers = true;
}

export enum EventType {
    Ban = "BAN", 
    ConfigUpdate = "CONFIG_UPDATE",
    LevelUp = "LEVEL_UP",
    MessageDeleted = "MESSAGE_DELETED",
    MemberJoin = "MEMBER_JOIN",
    MemberLeave = "MEMBER_LEAVE",
    Unban = "UNBAN", 
    Warn ="WARN"
}

Is there a conventional way to share types between TypeScript projects?

2
  • 1
    I don't think so, you can put the two project in one project or create a api then get the types from http request Commented May 5, 2020 at 15:17
  • 1
    An enum is not only a type, it's also a value. So it would make perfect sense to create an npm package for it if you need to share it across projects. Commented May 5, 2020 at 15:19

1 Answer 1

2

TypeScript does have support for sharing code between projects. However, that does not cater to you if you've got the projects split across multiple repositories:

https://www.typescriptlang.org/docs/handbook/project-references.html

If you need to split your project into different repositories, I would suggest publishing npm packages to a private package repository:

https://docs.npmjs.com/creating-and-publishing-private-packages

If you are the only developer and mostly using your own machine, then you could use locally installed packages:

Installing a local module using npm?

Sign up to request clarification or add additional context in comments.

1 Comment

Please note that you require a paid account to publish private package: Before you can publish private user-scoped npm packages, you must sign up for a paid npm user account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.