Skip to content

Prevent infinite recursion resolving nested conditional types with import types in them #32097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5035,8 +5035,10 @@ namespace ts {
return Debug.assertNever(propertyName);
}

// Pop an entry from the type resolution stack and return its associated result value. The result value will
// be true if no circularities were detected, or false if a circularity was found.
/**
* Pop an entry from the type resolution stack and return its associated result value. The result value will
* be true if no circularities were detected, or false if a circularity was found.
*/
function popTypeResolution(): boolean {
resolutionTargets.pop();
resolutionPropertyNames.pop();
Expand Down Expand Up @@ -11404,7 +11406,8 @@ namespace ts {

function maybeTypeParameterReference(node: Node) {
return !(node.kind === SyntaxKind.QualifiedName ||
node.parent.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>node.parent).typeArguments && node === (<TypeReferenceNode>node.parent).typeName);
node.parent.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>node.parent).typeArguments && node === (<TypeReferenceNode>node.parent).typeName ||
node.parent.kind === SyntaxKind.ImportType && (node.parent as ImportTypeNode).typeArguments && node === (node.parent as ImportTypeNode).qualifier);
}

function isTypeParameterPossiblyReferenced(tp: TypeParameter, node: Node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/nestedGenericConditionalTypeWithGenericImportType.ts] ////

//// [name.ts]
// #31824

export type Name<T> = any;

//// [index.ts]
type T<X> = any extends ((any extends any ? any : string) extends any ? import("./name").Name<X> : any)
? any
: any;


//// [name.js]
"use strict";
// #31824
exports.__esModule = true;
//// [index.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/name.ts ===
// #31824

export type Name<T> = any;
>Name : Symbol(Name, Decl(name.ts, 0, 0))
>T : Symbol(T, Decl(name.ts, 2, 17))

=== tests/cases/compiler/index.ts ===
type T<X> = any extends ((any extends any ? any : string) extends any ? import("./name").Name<X> : any)
>T : Symbol(T, Decl(index.ts, 0, 0))
>X : Symbol(X, Decl(index.ts, 0, 7))
>Name : Symbol(Name, Decl(name.ts, 0, 0))
>X : Symbol(X, Decl(index.ts, 0, 7))

? any
: any;

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/name.ts ===
// #31824

export type Name<T> = any;
>Name : any

=== tests/cases/compiler/index.ts ===
type T<X> = any extends ((any extends any ? any : string) extends any ? import("./name").Name<X> : any)
>T : any

? any
: any;

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #31824

// @filename: name.ts
export type Name<T> = any;

// @filename: index.ts
type T<X> = any extends ((any extends any ? any : string) extends any ? import("./name").Name<X> : any)
? any
: any;
2 changes: 1 addition & 1 deletion tests/cases/user/prettier/prettier
Submodule prettier updated 174 files