Skip to content

typeAlias = type, however, definition to convert types resolution into a hierarchy(Tree) for enhanced display, granularity control #24520

Closed
@wesleyolis

Description

@wesleyolis

The ability to allow type resolution of typescript for design time behaviour to not always resolve down to its base primitives, would help in communicate which type names should be used at the different layers of code composition. It would be nicer to see a modules type or an alternative internal named type instead of a primitive type. Currently this can be achieved by using interface names, however, I do feel it can be clumb some and potentially with structural typing not always a good thing.

It would be great to just define alias type using 'typeAlias', instead other more detail methods previously mention and similar to other languages, which is used to control the granularity.

When a type is resolved I would imagine that it would be presented in graphical tree eventually,
were the first typeAlias or interface token/node encountered would be the top level entry. Their after any typeAlias definitions on the path to resolving a type to its primitive are added as child elements.
This would allow the operator to decide the level of detail nessary to resolve his typing issues and peel back as many type layers as required, by expanding the child items.

[] Square brackets communicate this is a resolved type and their are potentially many types between this and the primitive.

It may still be useful to show all type redefinition for debugging purposes, in which case a different tree child symbol could be used, which is clickable on to communicate this. !->

Examples:

Case 1

Code

type A = boolean
type B = A
type C = B
interface/class D implemented/extends C {}
typeAlias E = D
type F = E
type G = F
typeAlias H = G
type I = H

Tree:

! H = G [boolean] // In Square brackets the most base type
 -> E  = D  [C] // Here present in square brackets, last successive child item type, probably too verbose
     !-> D = C
            |-> A = boolean

Case 2

Code

type A = string
type B = A
typeAlias C = B

Tree:

! C = [string] //square brackets communicate this is resolved type.

Case 3

Code

interface/class D implements/extends C
type A = string
type B = A
typeAlias C = B

Tree:

D = C [string]
   |->C = [string]

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions