mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
TS: Avoid infinite recursion in stringifyType
This commit is contained in:
@@ -436,7 +436,10 @@ export class TypeTable {
|
||||
let toStringValue: string;
|
||||
// Some types can't be stringified. Just discard the type if we can't stringify it.
|
||||
try {
|
||||
toStringValue = this.typeChecker.typeToString(type);
|
||||
toStringValue = this.typeChecker.typeToString(
|
||||
type,
|
||||
undefined,
|
||||
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
||||
} catch (e) {
|
||||
console.warn("Recovered from a compiler crash while stringifying a type. Discarding the type.");
|
||||
console.warn(e.stack);
|
||||
@@ -454,7 +457,11 @@ export class TypeTable {
|
||||
// Some types can't be stringified. Just discard the type if we can't stringify it.
|
||||
try {
|
||||
toStringValue =
|
||||
this.typeChecker.signatureToString(signature, signature.declaration, ts.TypeFormatFlags.None, kind);
|
||||
this.typeChecker.signatureToString(
|
||||
signature,
|
||||
signature.declaration,
|
||||
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope,
|
||||
kind);
|
||||
} catch (e) {
|
||||
console.warn("Recovered from a compiler crash while stringifying a signature. Discarding the signature.");
|
||||
console.warn(e.stack);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
| test.ts:3:1:7:6 | type Di ... \\n T; | Disjunction<T> |
|
||||
| test.ts:9:8:9:65 | type Tr ... n<T>>>; | Disjunction<Disjunction<Disjunction<T>>> |
|
||||
@@ -0,0 +1,4 @@
|
||||
import javascript
|
||||
|
||||
from TypeAliasDeclaration decl
|
||||
select decl, decl.getDefinition().getType()
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ArrayBox, Box } from 'somewhere';
|
||||
|
||||
type Disjunction<T> =
|
||||
T extends ArrayBox<infer U1> ? U1[] :
|
||||
T extends Box<infer U2> ? U2 :
|
||||
T extends ({[P in keyof T]: T[P]} & {p: any}) ? {[P in Exclude<keyof T, 'p'>]: Disjunction<T[P]>} :
|
||||
T;
|
||||
|
||||
export type Triple<T> = Disjunction<Disjunction<Disjunction<T>>>;
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
Reference in New Issue
Block a user