TS: Avoid infinite recursion in stringifyType

This commit is contained in:
Asger F
2019-06-28 10:24:34 +01:00
parent d2f8029625
commit f5569b8b58
5 changed files with 25 additions and 2 deletions

View File

@@ -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);

View File

@@ -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>>> |

View File

@@ -0,0 +1,4 @@
import javascript
from TypeAliasDeclaration decl
select decl, decl.getDefinition().getType()

View File

@@ -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>>>;