TsUML2 icon indicating copy to clipboard operation
TsUML2 copied to clipboard

Is it possible to model Typescript `type`s not just interface and Classes

Open rpocklin opened this issue 3 years ago • 7 comments

I am using types instead of interfaces and classes eg.

type Something = {
   name: string
   value: number
   user: User
}```

with many types containing other types (eg. a hierarchy similar to the demo) but when running tsuml I get the following (as though it can't parse it, but it is valid Typescript):

render to svg Error: Parse error on line 3:

^ Expecting 'IDENT', '[', got 'EOF' Error: Parse error on line 3:

^ Expecting 'IDENT', '[', got 'EOF' at Parser.parseError (/Users/.../node_modules/nomnoml/dist/nomnoml.js:806:25) at Parser.parse (/Users/.../node_modules/nomnoml/dist/nomnoml.js:867:26) at intermediateParse (/Users/.../node_modules/nomnoml/dist/nomnoml.js:1392:34) at parse (/Users/.../node_modules/nomnoml/dist/nomnoml.js:1312:25) at parseAndRender (/Users/.../node_modules/nomnoml/dist/nomnoml.js:2159:29) at Object.renderSvg (/Users/.../node_modules/nomnoml/dist/nomnoml.js:2175:34) at renderNomnomlSVG (/Users/.../node_modules/tsuml2/dist/core/io.js:30:20) at createNomnomlSVG (/Users/.../node_modules/tsuml2/dist/core/index.js:93:41) at /Users/.../node_modules/tsuml2/dist/bin/index.js:18:41 at Object. (/Users/.../node_modules/tsuml2/dist/bin/index.js:24:3) { hash: { text: '', token: 'EOF', line: 2, loc: { first_line: 1, last_line: 3, first_column: 0, last_column: 0 }, expected: [ "'IDENT'", "'['" ] } }```

rpocklin avatar May 14 '22 12:05 rpocklin

I can take a look. Of course it totally makes sense to support types (similarily to interfaces)

demike avatar May 16 '22 11:05 demike

@rpocklin I implemented type parsing. But I want to be shure the above error is gone. Can you send me a minimal reproduction of your problem?

demike avatar May 17 '22 10:05 demike

Sure, use the file test.ts with the contents:

export type X =
  | "a"
  | "b"

Then I run it with node ./node_modules/tsuml2/dist/bin/index.js -g ./test.ts

and it gives:

parsing source files:
/Users/.../test.ts

emitting declarations:
/Users/.../test.ts

render to svg
Error: Parse error on line 3:

^
Expecting 'IDENT', '[', got 'EOF' Error: Parse error on line 3:

^
Expecting 'IDENT', '[', got 'EOF'

rpocklin avatar May 17 '22 13:05 rpocklin

That's what I call a minimal reproduction 👍 In this case the problem was that not a single entity could be emitted and therefore nomnoml complained about that.

Now an error message will be shown in such a case.

By the way

export type X =
  | "a"
  | "b"

will not produce an entity now (open for suggestions). For now only types like

export type T = {
  a: number;
  doSomething(): void;
}

will produce output.

Can you give 0.5.1 a try

demike avatar May 18 '22 06:05 demike

Yep, that works, in terms of generating the separate boxes, one for each object type, nice! Is it possible to have types link to dependent types in the SVG eg.

export type X = {
  a: string;
  b: number;
}

export type Y = {
a: X;
c: number;

rpocklin avatar May 28 '22 06:05 rpocklin

Adding this functionality is on my list. I have to investigate the possible relations: https://d3n817fwly711g.cloudfront.net/blog/wp-content/uploads/2012/03/Class-Diagram-Relationships.png Multiplicity ... (open for suggestions)

demike avatar May 29 '22 19:05 demike

@rpocklin member associations can be rendered now in v0.6.1 If the member is an array "0..*" is added in addition to the assocation line. Would be nice if you can try it out use the -m command line parameter

And thanks for the constructive comments

demike avatar Jun 13 '22 20:06 demike

Implemented v0.6.1

demike avatar Oct 02 '22 06:10 demike