( diagnostic: ts.Diagnostic | ts.DiagnosticRelatedInformation, guard: (node: ts.Node) => node is T, )
| 167 | } |
| 168 | |
| 169 | export function diagnosticToNode<T extends ts.Node>( |
| 170 | diagnostic: ts.Diagnostic | ts.DiagnosticRelatedInformation, |
| 171 | guard: (node: ts.Node) => node is T, |
| 172 | ): T { |
| 173 | const diag = diagnostic as ts.Diagnostic | ts.DiagnosticRelatedInformation; |
| 174 | if (diag.file === undefined) { |
| 175 | throw new Error(`Expected ts.Diagnostic to have a file source`); |
| 176 | } |
| 177 | const node = getTokenAtPosition(diag.file, diag.start!); |
| 178 | expect(guard(node)).toBe(true); |
| 179 | return node as T; |
| 180 | } |
no test coverage detected
searching dependent graphs…