bafolts / tplant

Typescript to plantuml
https://segmentationfaults.com/tplant/default.html
GNU General Public License v3.0
262 stars 34 forks source link

Support TS Utility Types #90

Open giffeler opened 2 years ago

giffeler commented 2 years ago

TypeScript provides several utility types to facilitate common type transformations. These utilities are available globally.

interface Todo {
  title: string;
  description: string;
  completed: boolean;
  createdAt: number;
}

class MyTodo implements omit<Todo, "createdAt"> {
…
}

Utility Types should be considered in the presentation of the class diagrams. Currently, they are incorrectly listed as independent instances.

adrian-burlacu-software commented 2 years ago

Agreed. I took a look at the page: https://www.typescriptlang.org/docs/handbook/utility-types.html

The first three are somewhat OK -- i.e. Partial, Required, Readonly but the text description lacks the actual utility type. After Record<Keys, Type> it gets muddy what should or should not happen.

Mostly an issue with Utility types that have 2 type parameters -- i.e. why did the TS API even not reverse this Record<Keys, Type> to be Record<Type, Keys>. Again, the single parameter Utility types need to specify their text better: some come out any, unknown or the parameter type.

adrian-burlacu-software commented 2 years ago

@bafolts I would actually treat this as a bug than an enhancement because it doesn't respect the JavaScript coding API. My suggestion is to create a Components.Type class, move the Type.Filename property there, and nest them.

I might look into fixing this later this year when I get a chance. Also, I'm wondering if maybe it would help to possibly generate and load the typings .d.ts files to do all this analysis...