@@ -115,31 +115,39 @@ namespace Harness {
115115 // let type = this.checker.getTypeAtLocation(node);
116116 let type = ts . isExpressionWithTypeArgumentsInClassExtendsClause ( node . parent ) ? this . checker . getTypeAtLocation ( node . parent ) : undefined ;
117117 if ( ! type || type . flags & ts . TypeFlags . Any ) type = this . checker . getTypeAtLocation ( node ) ;
118- const typeString =
119- // Distinguish `errorType`s from `any`s; but only if the file has no errors.
120- // Additionally,
121- // * the LHS of a qualified name
122- // * a binding pattern name
123- // * labels
124- // * the "global" in "declare global"
125- // * the "target" in "new.target"
126- // * names in import statements
127- // * type-only names in export statements
128- // * and intrinsic jsx tag names
129- // return `error`s via `getTypeAtLocation`
130- // But this is generally expected, so we don't call those out, either
131- ( ! this . hadErrorBaseline &&
132- type . flags & ts . TypeFlags . Any &&
133- ! ts . isBindingElement ( node . parent ) &&
134- ! ts . isPropertyAccessOrQualifiedName ( node . parent ) &&
135- ! ts . isLabelName ( node ) &&
136- ! ( ts . isModuleDeclaration ( node . parent ) && ts . isGlobalScopeAugmentation ( node . parent ) ) &&
137- ! ts . isMetaProperty ( node . parent ) &&
138- ! this . isImportStatementName ( node ) &&
139- ! this . isExportStatementName ( node ) &&
140- ! this . isIntrinsicJsxTag ( node ) ) ?
141- ( type as ts . IntrinsicType ) . intrinsicName :
142- this . checker . typeToString ( type , node . parent , ts . TypeFormatFlags . NoTruncation | ts . TypeFormatFlags . AllowUniqueESSymbolType ) ;
118+ // Distinguish `errorType`s from `any`s; but only if the file has no errors.
119+ // Additionally,
120+ // * the LHS of a qualified name
121+ // * a binding pattern name
122+ // * labels
123+ // * the "global" in "declare global"
124+ // * the "target" in "new.target"
125+ // * names in import statements
126+ // * type-only names in export statements
127+ // * and intrinsic jsx tag names
128+ // return `error`s via `getTypeAtLocation`
129+ // But this is generally expected, so we don't call those out, either
130+ let typeString : string ;
131+ if ( ! this . hadErrorBaseline &&
132+ type . flags & ts . TypeFlags . Any &&
133+ ! ts . isBindingElement ( node . parent ) &&
134+ ! ts . isPropertyAccessOrQualifiedName ( node . parent ) &&
135+ ! ts . isLabelName ( node ) &&
136+ ! ( ts . isModuleDeclaration ( node . parent ) && ts . isGlobalScopeAugmentation ( node . parent ) ) &&
137+ ! ts . isMetaProperty ( node . parent ) &&
138+ ! this . isImportStatementName ( node ) &&
139+ ! this . isExportStatementName ( node ) &&
140+ ! this . isIntrinsicJsxTag ( node ) ) {
141+ typeString = ( type as ts . IntrinsicType ) . intrinsicName ;
142+ }
143+ else {
144+ typeString = this . checker . typeToString ( type , node . parent , ts . TypeFormatFlags . NoTruncation | ts . TypeFormatFlags . AllowUniqueESSymbolType ) ;
145+ if ( ts . isIdentifier ( node ) && ts . isTypeAliasDeclaration ( node . parent ) && node . parent . name === node && typeString === ts . idText ( node ) ) {
146+ // for a complex type alias `type T = ...`, showing "T : T" isn't very helpful for type tests. When the type produced is the same as
147+ // the name of the type alias, recreate the type string without reusing the alias name
148+ typeString = this . checker . typeToString ( type , node . parent , ts . TypeFormatFlags . NoTruncation | ts . TypeFormatFlags . AllowUniqueESSymbolType | ts . TypeFormatFlags . InTypeAlias ) ;
149+ }
150+ }
143151 return {
144152 line : lineAndCharacter . line ,
145153 syntaxKind : node . kind ,
0 commit comments