question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to find all the types involved in a node?

See original GitHub issue

How to find all the types involved in a node?

export const TraceConfiguration = {
	register(container?: IContainer): void {
		Object.assign(Tracer, DebugTracer);
	}
};

These types: IContainer, Tracer, DebugTracer for TraceConfiguration node.

or

export type BindingWithBehavior = IBinding & {
    sourceExpression: BindingBehaviorExpression;
};

These types: IBinding , BindingBehaviorExpression for BindingWithBehavior node.

No matter what is the node (Variable, Class, Literal, …) or where is the type (in Parameter, Block, Union, … ).

I want to access all available type.getText() in the whole node.

Does exist any general way to find out whole types that are used in a node? or I should define a specific functionality for each use case.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dsherretcommented, Oct 5, 2019

Oh sorry, I misread your question originally. You may have to do:

const types = new Set<Type>();
node.forEachDescendant(descendant => {
    if (TypeGuards.isTypedNode(descendant) || TypeGuards.isIdentifier(descendant))
        types.add(descendant.getType());
    else if (TypeGuards.isReturnTypedNode(descendant))
        types.add(descendant.getReturnType());
});

That will get implicit types as well. You may want to filter out any types when you’re done (check Type#isAny())

3reactions
dsherretcommented, Oct 5, 2019

@HamedFathi I think you could just do:

const types = new Set<Type>();
node.forEachDescendant(descendant => {
    if (TypeGuards.isTypeNode(descendant))
        types.add(descendant.getType());
});

// or in 4.2.0 (just released)
const types = new Set<Type>(node.forEachDescendantAsArray().filter(TypeGuards.isTypeNode).map(d => d.getType()));

That won’t get all the implicit types in there though.

Side note: Using forEachDescendantAsArray is slightly more efficient than using getDescendants() because getDescendants() will return parsed out token nodes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get all nodes of given type - Drupal Answers - Stack Exchange
I know I can get all the nodes (of any type) with \Drupal\node\Entity\Node::loadMultiple() and the list of all types by \Drupal\node\Entity\NodeType:: ...
Read more >
Node.nodeType - Web APIs - MDN Web Docs - Mozilla
The read-only nodeType property of a Node interface is an integer that identifies what the node is. It distinguishes different kind of nodes...
Read more >
Find all reachable nodes from every node present in a given set
One straight forward solution is to do a BFS traversal for every node present in the set and then find all the reachable...
Read more >
Node properties: type, tag and contents
The “nodeType” property ... The nodeType property provides one more, “old-fashioned” way to get the “type” of a DOM node. It has a...
Read more >
How to find all nodes of a specific type in XPath - Stack Overflow
try this "//fruit-name". It shall find all fruitnames wherever they are in the document hierarchy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found