Consider the following model structure:
interface Address{
country: string;
}
interface Author{
authorId: number;
authorName:string;
address: Address;
}
interface Book{
bookId:string;
title: string;
author : Author;
}
I want to iterate through all the properties of the Book interface.
const bookType = // obtain the type node of Book
const stack: any[] = [...bookType.getProperties()];
const props: any[] = [];
while (stack.length) {
const prop = stack.pop();
props.push(prop);
if (checker.getTypeOfSymbolAtLocation(prop, node)) { //node is a ts.MethodDeclaration which returns a value of type Book
stack.push(...checker.getTypeOfSymbolAtLocation(prop, node).getProperties());
}
}
The code above successfully accomplishes this task, however, it also retrieves properties of built-in types like string, number etc., (e.g. toLocaleString, valueOf, toPrecision). I aim to specifically extract properties of custom types/interfaces and disregard built-in types.