mermaid
mermaid copied to clipboard
Cannot have Generic of Generics in Class diagram
Describe the bug In the class diagram we can use ~ to achieve <T> generic types, for instance:
classDiagram
MyInterface: +StateFlow~Int~
But we cannot have Generic of generic <T<K>>, for instnace:
classDiagram
MyInterface: +StateFlow~List~Something~~
and the result is:
+StateFlow<List>Something<>
Related to #1120 and #1063
Also related, these types of class diagrams with overloads of generic parameters do not render correctly either.
classDiagram
class A~T~ {
+T value
}
class A~T,N~ {
}
class A~int~ {
}
A~int~ <|.. A~T~
Renders like:
classDiagram
class A~T~ {
+T value
}
class A~T,N~ {
}
class A~int~ {
}
A~int~ <|.. A~T~
You can have List~Something~T~~ ids
.
classDiagram
class A {
List~Something~T~~ ids
}
So the issue is only with Class having generic types at the top. It might be a bug with the grammar.
The nested generics is good but this doesn't yet seem to support lists of generics as commonly used for things like Map<K,V>. Trying to diagram a class member that's a Map of string identifiers to a specific set of function types and the comma separated list of generics seems to give the current implementation a curve ball it didn't expect and it displays tilde's instead of the generics brackets.
Example:
class MyDemo<T> {
private demoFns: Map<string, (s: T) => void>
}
classDiagram
class MyDemo~T~ {
#demoFns: Map~string, (s: T) => void~
}
classDiagram
class MyDemo~T~ {
#demoFns: Map~string, (s: T) => void~
}
Example:
class MyDemo<T> { private demoFns: Map<string, (s: T) => void> }
classDiagram class MyDemo~T~ { #demoFns: Map~string, (s: T) => void~ }
So you mean specifically when you use a => statement, since the parser trips on the bracket after the equals?
Apologies, I was thinking it was for the lack of generic list support but in testing with a fresh look it seems to handle the list of generics just fine.
Test:
class MyDemo<X,Y> {
private xVector: X
private yVector: Y
}
classDiagram
class MyDemo~X,Y~ {
#xVector: X
#yVector: Y
}
Seems to also work with default type specifications:
class MyDemo<X=Vector,Y=Vector> {
private xVector: X
private yVector: Y
}
classDiagram
class MyDemo~X=Vector,Y=Vector~ {
#xVector: X
#yVector: Y
}
However, in coming up with an example that avoids the js shorthand (thanks for pointing that out) I'm still seeing tilde's instead of brackets in what's generated.
class MyDemo<X,Y> {
tests: Map<string,(X,Y): void>
}
classDiagram
class MyDemo~X,Y~ {
tests: Map~string,(X,Y): void~
}
If I simplify the class members to mappings with a simple generic list I get a Maximum call stack size exceeded
error:
class MyDemo<X=any,Y=any> {
xTests: Map<string,X>
yTests: Map<string,Y>
}
classDiagram
class MyDemo~X,Y~ {
xTests: Map~string,X~
yTests: Map~string,Y~
}
Furthermore, if I try to express an anonymous object type mapping I get a Diagram error not found.
error I'm not sure how to begin unraveling.
class MyDemo<X,Y> {
tests: Map<string,{X,Y}>
}
classDiagram
class MyDemo~X,Y~ {
tests: Map~string,{X,Y}~
}
The parser is choking on two aspects of this.
- The curly braces signal a "struct_start"/"struct_end" section, inside of which there should be the class definition with members.
- Commas inside of a generic value start/stop
This is going to take a little more time to find the best way to address this