Created
July 17, 2025 20:07
-
-
Save souporserious/81b74ed995402f120284f76843b64217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const callStack: string[] = [] | |
const MAX_DEPTH = 1500 | |
const SNIPPET_LEN = 60 | |
function snippet(text: string) { | |
return text.replace(/\s+/g, ' ').slice(0, SNIPPET_LEN) | |
} | |
/** Traces the type and its enclosing node. */ | |
function traceType(type: Type, node?: Node) { | |
let nodeInfo = '' | |
if (node) { | |
const kindName = tsMorph.SyntaxKind[node.getKind()] | |
const location = node.getSourceFile() | |
? node.getStartLineNumber() + ':' + node.getStartLinePos() | |
: null | |
nodeInfo = ` • ${kindName}${location ? `@${location}` : ''} ➜ ${snippet(node.getText())}` | |
} | |
callStack.push( | |
`${snippet(type.getText(undefined, TYPE_FORMAT_FLAGS))}${nodeInfo}` | |
) | |
if (callStack.length > MAX_DEPTH) { | |
throw new Error( | |
'resolveType recursion depth exceeded > ' + | |
MAX_DEPTH + | |
'\n' + | |
callStack.join('\n ↳ ') | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment