-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Added typeToTypeNode with truncation #59332
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
Changes from 6 commits
f6e323c
9092688
44568f7
c1b1d40
52c2ff1
05431a6
5810eab
5891f32
90dade9
3b44569
2cbb9f3
ac4ba37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| addRange, | ||
| addRelatedInfo, | ||
| addSyntheticLeadingComment, | ||
| addSyntheticTrailingComment, | ||
| AliasDeclarationNode, | ||
| AllAccessorDeclarations, | ||
| AmbientModuleDeclaration, | ||
|
|
@@ -7054,6 +7055,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
|
|
||
| function createTypeNodesFromResolvedType(resolvedType: ResolvedType): TypeElement[] | undefined { | ||
| if (checkTruncationLength(context)) { | ||
| if (context.flags & NodeBuilderFlags.NoTruncation) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test that shows what this looks like?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you mentioned, there's no test for this scenario. I removed this check, and nothing regressed. I'm not sure how to test it but if it's utterly necessary I can address that another PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://app.codecov.io/gh/microsoft/TypeScript/pull/59332?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=checks&utm_campaign=pr+comments&utm_term=microsoft implies that this code is covered somewhere in a test. Maybe add an assert and reverse engineer a specific test from that?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After deeper analysis, the file Check line 18, for the last property
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was working on it. Added.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, you're saying that in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I mean, before this change files in After this change, See the test |
||
| return []; | ||
| } | ||
| return [factory.createPropertySignature(/*modifiers*/ undefined, "...", /*questionToken*/ undefined, /*type*/ undefined)]; | ||
| } | ||
| const typeElements: TypeElement[] = []; | ||
|
|
@@ -7085,7 +7089,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| } | ||
| } | ||
| if (checkTruncationLength(context) && (i + 2 < properties.length - 1)) { | ||
| typeElements.push(factory.createPropertySignature(/*modifiers*/ undefined, `... ${properties.length - i} more ...`, /*questionToken*/ undefined, /*type*/ undefined)); | ||
| if (context.flags & NodeBuilderFlags.NoTruncation) { | ||
| const typeElement = typeElements.pop()!; | ||
| typeElements.push(addSyntheticTrailingComment(typeElement, SyntaxKind.MultiLineCommentTrivia, `... ${properties.length - i} more ...`)); | ||
| } | ||
| else { | ||
| typeElements.push(factory.createPropertySignature(/*modifiers*/ undefined, `... ${properties.length - i} more ...`, /*questionToken*/ undefined, /*type*/ undefined)); | ||
| } | ||
| addPropertyToElementList(properties[properties.length - 1], context, typeElements); | ||
| break; | ||
| } | ||
|
|
@@ -7100,7 +7110,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| if (!(context.flags & NodeBuilderFlags.NoTruncation)) { | ||
| return factory.createTypeReferenceNode(factory.createIdentifier("..."), /*typeArguments*/ undefined); | ||
| } | ||
| return factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); | ||
| return addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, "elided"); | ||
| } | ||
|
|
||
| function shouldUsePlaceholderForProperty(propertySymbol: Symbol, context: NodeBuilderContext) { | ||
|
|
@@ -7259,7 +7269,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| function mapToTypeNodes(types: readonly Type[] | undefined, context: NodeBuilderContext, isBareList?: boolean): TypeNode[] | undefined { | ||
| if (some(types)) { | ||
| if (checkTruncationLength(context)) { | ||
| if (!isBareList) { | ||
| if (context.flags & NodeBuilderFlags.NoTruncation) { | ||
| return [addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, "elided")]; | ||
| } | ||
| else if (!isBareList) { | ||
| return [factory.createTypeReferenceNode("...", /*typeArguments*/ undefined)]; | ||
| } | ||
| else if (types.length > 2) { | ||
|
|
@@ -7278,6 +7291,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| for (const type of types) { | ||
| i++; | ||
| if (checkTruncationLength(context) && (i + 2 < types.length - 1)) { | ||
| if (context.flags & NodeBuilderFlags.NoTruncation) { | ||
|
||
| return [addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, "elided")]; | ||
|
||
| } | ||
| result.push(factory.createTypeReferenceNode(`... ${types.length - i} more ...`, /*typeArguments*/ undefined)); | ||
| const typeNode = typeToTypeNodeHelper(types[types.length - 1], context); | ||
| if (typeNode) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,6 @@ var C = /** @class */ (function () { | |
| declare class C { | ||
| static D: { | ||
| new (): {}; | ||
| D: any; | ||
| D: /*elided*/ any; | ||
| }; | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,6 +333,6 @@ declare let Anon: { | |
| }; | ||
| declare let OuterC: { | ||
| new <out T>(): { | ||
| foo(): any; | ||
| foo(): /*elided*/ any; | ||
| }; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.