Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add comments
  • Loading branch information
ahejlsberg committed Sep 23, 2021
commit 891f961765ca46181b0dd24c65dcdf7180226670
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4523,6 +4523,8 @@ namespace ts {
const noTruncation = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation;
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | (noTruncation ? NodeBuilderFlags.NoTruncation : 0), writer);
if (typeNode === undefined) return Debug.fail("should always get typenode");
// The unresolved type gets a synthesized comment on `any` to hint to users that it's not a plain `any`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to leave a comment on this one (pun intended).

Suggested change
const options = { removeComments: type !== unresolvedType };
// The unresolved type gets a synthesized comment on `any`
// to hint to users that it's not a plain `any`.
// Otherwise, we always strip comments out.
const options = { removeComments: type !== unresolvedType };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add a comment.

// Otherwise, we always strip comments out.
const options = { removeComments: type !== unresolvedType };
const printer = createPrinter(options);
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
Expand Down Expand Up @@ -8270,6 +8272,8 @@ namespace ts {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just this? Seems like it'd be cheaper too.

Suggested change
return type === errorType || !!(type.flags & TypeFlags.Any && type.aliasSymbol);
return type === errorType || type === unresolvedType;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that wouldn't work. I'll add a clarifying comment, but basically we want to identify the special TypeFlags.Any types produced by getTypeForTypeAliasReference for an unresolved symbol. The sole purpose of unresolvedType is to act as the declared type for the special type alias symbols we create for unresolved names. The type is never actually returned by anything because getTypeForTypeAliasReference maps it into a special TypeFlags.Any type with an aliasSymbol.

function isErrorType(type: Type) {
// The only 'any' types that have alias symbols are those manufactured by getTypeFromTypeAliasReference for
// a reference to an unresolved symbol. We want those to behave like the errorType.
return type === errorType || !!(type.flags & TypeFlags.Any && type.aliasSymbol);
}

Expand Down