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?

ADAMJR
  • 1,880
  • 1
  • 14
  • 34
  • 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 – devosu May 05 '20 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. – JJWesterkamp May 05 '20 at 15:19

1 Answers1

1

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?

maxpaj
  • 6,029
  • 5
  • 35
  • 56