diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9cbbb3a28bd5f..bb1d7e7ee3978 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9885,7 +9885,12 @@ namespace ts { } else { type = errorType; - error(isNamedDeclaration(declaration) ? declaration.name : declaration || declaration, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); + if (declaration.kind === SyntaxKind.JSDocEnumTag) { + error(declaration.typeExpression.type, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); + } + else { + error(isNamedDeclaration(declaration) ? declaration.name : declaration || declaration, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); + } } links.declaredType = type; } @@ -32799,7 +32804,7 @@ namespace ts { function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type { const tag = isInJSFile(node) ? getJSDocTypeTag(node) : undefined; if (tag) { - return checkAssertionWorker(tag, tag.typeExpression.type, node.expression, checkMode); + return checkAssertionWorker(tag.typeExpression.type, tag.typeExpression.type, node.expression, checkMode); } return checkExpression(node.expression, checkMode); } @@ -35043,12 +35048,14 @@ namespace ts { // Include the `<>` in the error message : rangeOfTypeParameters(sourceFile, parent.typeParameters!); const only = parent.typeParameters!.length === 1; + //TODO: following line is possible reason for bug #41974, unusedTypeParameters_TemplateTag const message = only ? Diagnostics._0_is_declared_but_its_value_is_never_read : Diagnostics.All_type_parameters_are_unused; const arg0 = only ? name : undefined; addDiagnostic(typeParameter, UnusedKind.Parameter, createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, message, arg0)); } } else { + //TODO: following line is possible reason for bug #41974, unusedTypeParameters_TemplateTag addDiagnostic(typeParameter, UnusedKind.Parameter, createDiagnosticForNode(typeParameter, Diagnostics._0_is_declared_but_its_value_is_never_read, name)); } } diff --git a/tests/baselines/reference/enumTagCircularReference.errors.txt b/tests/baselines/reference/enumTagCircularReference.errors.txt index 891434394f377..78cea76076ca4 100644 --- a/tests/baselines/reference/enumTagCircularReference.errors.txt +++ b/tests/baselines/reference/enumTagCircularReference.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/jsdoc/bug27142.js(1,5): error TS2456: Type alias 'E' circularly references itself. +tests/cases/conformance/jsdoc/bug27142.js(1,12): error TS2456: Type alias 'E' circularly references itself. ==== tests/cases/conformance/jsdoc/bug27142.js (1 errors) ==== /** @enum {E} */ - ~~~~~~~~~~ + ~ !!! error TS2456: Type alias 'E' circularly references itself. const E = { x: 0 }; \ No newline at end of file diff --git a/tests/baselines/reference/jsdocImportTypeNodeNamespace.errors.txt b/tests/baselines/reference/jsdocImportTypeNodeNamespace.errors.txt index 571c3f52cbbcb..88f0c031be087 100644 --- a/tests/baselines/reference/jsdocImportTypeNodeNamespace.errors.txt +++ b/tests/baselines/reference/jsdocImportTypeNodeNamespace.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/Main.js(2,14): error TS2352: Conversion of type 'string' to type 'typeof _default' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/compiler/Main.js(2,21): error TS2352: Conversion of type 'string' to type 'typeof _default' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. ==== tests/cases/compiler/GeometryType.d.ts (0 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/Main.js(2,14): error TS2352: Conversion of type 'string' to ==== tests/cases/compiler/Main.js (1 errors) ==== export default function () { return /** @type {import('./GeometryType.js').default} */ ('Point'); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Conversion of type 'string' to type 'typeof _default' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. } \ No newline at end of file diff --git a/tests/baselines/reference/jsdocTypeTagCast.errors.txt b/tests/baselines/reference/jsdocTypeTagCast.errors.txt index fb4487c036906..41544f603485c 100644 --- a/tests/baselines/reference/jsdocTypeTagCast.errors.txt +++ b/tests/baselines/reference/jsdocTypeTagCast.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/jsdoc/b.js(4,13): error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. -tests/cases/conformance/jsdoc/b.js(45,16): error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/conformance/jsdoc/b.js(4,20): error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/conformance/jsdoc/b.js(45,23): error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'. -tests/cases/conformance/jsdoc/b.js(49,19): error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/conformance/jsdoc/b.js(49,26): error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Type 'SomeOther' is missing the following properties from type 'SomeDerived': x, p -tests/cases/conformance/jsdoc/b.js(51,17): error TS2352: Conversion of type 'SomeDerived' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/conformance/jsdoc/b.js(51,24): error TS2352: Conversion of type 'SomeDerived' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'. -tests/cases/conformance/jsdoc/b.js(52,17): error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +tests/cases/conformance/jsdoc/b.js(52,24): error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'. tests/cases/conformance/jsdoc/b.js(58,1): error TS2322: Type 'SomeFakeClass' is not assignable to type 'SomeBase'. Types of property 'p' are incompatible. @@ -26,7 +26,7 @@ tests/cases/conformance/jsdoc/b.js(67,8): error TS2454: Variable 'numOrStr' is u var W = /** @type {string} */(/** @type {*} */ (4)); var W = /** @type {string} */(4); // Error - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. /** @type {*} */ @@ -69,7 +69,7 @@ tests/cases/conformance/jsdoc/b.js(67,8): error TS2454: Variable 'numOrStr' is u someBase = /** @type {SomeBase} */(someDerived); someBase = /** @type {SomeBase} */(someBase); someBase = /** @type {SomeBase} */(someOther); // Error - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~ !!! error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. !!! error TS2352: Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'. !!! related TS2728 tests/cases/conformance/jsdoc/b.js:17:9: 'p' is declared here. @@ -77,17 +77,17 @@ tests/cases/conformance/jsdoc/b.js(67,8): error TS2454: Variable 'numOrStr' is u someDerived = /** @type {SomeDerived} */(someDerived); someDerived = /** @type {SomeDerived} */(someBase); someDerived = /** @type {SomeDerived} */(someOther); // Error - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. !!! error TS2352: Type 'SomeOther' is missing the following properties from type 'SomeDerived': x, p someOther = /** @type {SomeOther} */(someDerived); // Error - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS2352: Conversion of type 'SomeDerived' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. !!! error TS2352: Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'. !!! related TS2728 tests/cases/conformance/jsdoc/b.js:28:9: 'q' is declared here. someOther = /** @type {SomeOther} */(someBase); // Error - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. !!! error TS2352: Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'. !!! related TS2728 tests/cases/conformance/jsdoc/b.js:28:9: 'q' is declared here.