Skip to content

Commit f5569b8

Browse files
committed
TS: Avoid infinite recursion in stringifyType
1 parent d2f8029 commit f5569b8

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

javascript/extractor/lib/typescript/src/type_table.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ export class TypeTable {
436436
let toStringValue: string;
437437
// Some types can't be stringified. Just discard the type if we can't stringify it.
438438
try {
439-
toStringValue = this.typeChecker.typeToString(type);
439+
toStringValue = this.typeChecker.typeToString(
440+
type,
441+
undefined,
442+
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
440443
} catch (e) {
441444
console.warn("Recovered from a compiler crash while stringifying a type. Discarding the type.");
442445
console.warn(e.stack);
@@ -454,7 +457,11 @@ export class TypeTable {
454457
// Some types can't be stringified. Just discard the type if we can't stringify it.
455458
try {
456459
toStringValue =
457-
this.typeChecker.signatureToString(signature, signature.declaration, ts.TypeFormatFlags.None, kind);
460+
this.typeChecker.signatureToString(
461+
signature,
462+
signature.declaration,
463+
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope,
464+
kind);
458465
} catch (e) {
459466
console.warn("Recovered from a compiler crash while stringifying a signature. Discarding the signature.");
460467
console.warn(e.stack);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.ts:3:1:7:6 | type Di ... \\n T; | Disjunction<T> |
2+
| test.ts:9:8:9:65 | type Tr ... n<T>>>; | Disjunction<Disjunction<Disjunction<T>>> |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from TypeAliasDeclaration decl
4+
select decl, decl.getDefinition().getType()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ArrayBox, Box } from 'somewhere';
2+
3+
type Disjunction<T> =
4+
T extends ArrayBox<infer U1> ? U1[] :
5+
T extends Box<infer U2> ? U2 :
6+
T extends ({[P in keyof T]: T[P]} & {p: any}) ? {[P in Exclude<keyof T, 'p'>]: Disjunction<T[P]>} :
7+
T;
8+
9+
export type Triple<T> = Disjunction<Disjunction<Disjunction<T>>>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)