36

I'm using Visual Studio 2015 to create Web Apps and I just start using TypeScript.

As my project gets bigger, I'm wondering if there's a way to get UML diagram of TypeScript code using Visual Studio, extensions or any other free tool.

Mhd
  • 2,778
  • 5
  • 22
  • 59
  • 1
    Keep in mind that some solutions such as TsUML will upload your code without telling you. – JSON Jun 23 '22 at 01:29

7 Answers7

33

I am using a VSC extension named classdiagram-ts from AlexShen that does a very nice job, it can be used for creating a diagram for a file or a folder and also lets you reposition and navigate to fields, hide members and other cool options.

https://marketplace.visualstudio.com/items?itemName=AlexShen.classdiagram-ts&ssr=false#overview

Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59
  • Layout with this tool does not seem sophisticated, compared to GraphViz (PlantUML). It just puts classes horizontally. You'll have to spend time moving them around to see everything. – Fuhrmanator Feb 10 '21 at 17:58
  • 1
    Be aware this is not open source: "It's a personal close source project, no public repo." – lys Dec 23 '22 at 01:06
10

You can try tplant. Here's an example for the typescript classes at https://github.com/pascalerni/abap2famix/tree/master/src

tplant with Compositions option turned on

Another alternative, which I currently use but requires VSCode, is: vscode-ts-uml

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
zmf
  • 542
  • 6
  • 9
6

I would advise against doing anything with TsUML. You install it as a regular NPM package, but then it uses some sketchy online service. It seems dangerous to use Tsuml for proprietary projects.

Mattマット
  • 81
  • 1
  • 4
4

for Visual Studio : https://marketplace.visualstudio.com/items?itemName=AzadRatzki.TypeScriptDiagram#overview

for vscode : https://github.com/remojansen/TsUML

or

I would suggest commenting your TypeScript code using the JSDoc convention, compile your TS code without stripping off comments (removeComments to false in tsconfig.json), and use a documentation generator on the JS files.

Based on that, you could maybe find a tool to generate UML diagram from JSDoc : JSDoc UML Diagram

1

Using TsUML:

npm install -g tsuml
# Note: this posts data to https://yuml.me!!
tsuml --glob ./src/**/*.ts
Fabian Kleiser
  • 2,988
  • 3
  • 27
  • 44
Breck
  • 670
  • 2
  • 7
  • 22
1

I found a very useful site to convert TS to UML diagram

https://tsuml-demo.firebaseapp.com/

copy following code and paste it under Typescript Tab

export class BaseDTO {
  created: number;
  createdBy: string;
  updated: number;
  updatedBy: string;
}

export class PaymentDTO extends BaseDTO {
  paymentId: number;
  paymentReference: string;
  amount: string;
  paymentPayee: { name: string }
}

Example:

enter image description here

khizer
  • 1,242
  • 15
  • 13
1

There is now an open-source package called TsUML2 that, in their words:

works offline, so no third party servers are involved.

https://github.com/demike/TsUML2

lys
  • 949
  • 2
  • 9
  • 33