Skip to content
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
6 changes: 6 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
})
}

isJS := sourceFile.ScriptKind == core.ScriptKindJS || sourceFile.ScriptKind == core.ScriptKindJSX
isCheckJS := isJS && ast.IsCheckJSEnabledForFile(sourceFile, compilerOptions)
if isCheckJS {
diags = append(diags, sourceFile.JSDocDiagnostics()...)
}

filtered, directivesByLine := p.getDiagnosticsWithPrecedingDirectives(sourceFile, diags)
for _, directive := range directivesByLine {
// Above we changed all used directive kinds to @ts-ignore, so any @ts-expect-error directives that
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a.js(1,12): error TS1110: Type expected.


==== a.js (1 errors) ====
/** @type {@import("a").Type} */
~
!!! error TS1110: Type expected.
let x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [tests/cases/compiler/invalidJsdocType.ts] ////

=== a.js ===
/** @type {@import("a").Type} */
let x;
>x : Symbol(x, Decl(a.js, 1, 3))

7 changes: 7 additions & 0 deletions testdata/baselines/reference/compiler/invalidJsdocType.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [tests/cases/compiler/invalidJsdocType.ts] ////

=== a.js ===
/** @type {@import("a").Type} */
let x;
>x : any

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
enumDef.js(14,21): error TS1003: Identifier expected.
enumDef.js(16,18): error TS2339: Property 'Blah' does not exist on type '{ Action: { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; }; }'.
index.js(4,17): error TS2503: Cannot find namespace 'Host'.
index.js(8,21): error TS2304: Cannot find name 'Host'.
index.js(13,11): error TS2503: Cannot find namespace 'Host'.
index.js(18,11): error TS2503: Cannot find namespace 'Host'.


==== enumDef.js (1 errors) ====
==== enumDef.js (2 errors) ====
var Host = {};
Host.UserMetrics = {};
/** @enum {number} */
Expand All @@ -20,7 +21,10 @@ index.js(18,11): error TS2503: Cannot find namespace 'Host'.
*/
/**
* @typedef {string}

*/

!!! error TS1003: Identifier expected.
Host.UserMetrics.Blah = {
~~~~
!!! error TS2339: Property 'Blah' does not exist on type '{ Action: { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; }; }'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/a.js(1,13): error TS1098: Type parameter list cannot be empty.
/a.js(1,14): error TS1139: Type parameter declaration expected.


==== /a.js (1 errors) ====
==== /a.js (2 errors) ====
/** @param {<} x */
~~
!!! error TS1098: Type parameter list cannot be empty.
~
!!! error TS1139: Type parameter declaration expected.
function f(x) {}

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
example.js(3,11): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
example.js(3,19): error TS1005: '}' expected.


==== example.js (1 errors) ====
==== example.js (2 errors) ====
// @ts-check
/**
* @type {function(@foo)}
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
*/
let x;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
a.js(5,18): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'?
a.js(5,28): error TS1005: ';' expected.


==== a.js (2 errors) ====
==== a.js (3 errors) ====
/** @type {unique symbol} */
const foo = Symbol();

Expand All @@ -12,4 +13,6 @@ a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type h
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
~~~
!!! error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'?
~~~~~~~
!!! error TS1005: ';' expected.

Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
file.js(2,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
file.js(2,20): error TS1005: '}' expected.
file.js(6,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
file.js(6,20): error TS1005: '}' expected.
file.js(10,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
file.js(10,20): error TS1005: '}' expected.
file.js(16,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
file.js(16,20): error TS1005: '}' expected.
file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
file.js(21,20): error TS1005: '}' expected.


==== file.js (5 errors) ====
==== file.js (10 errors) ====
// Error (good)
/** @type {function(): string} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const a = () => 0

// Error (good)
/** @type {function(): string} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const b = async () => 0

// No error (bad)
/** @type {function(): string} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const c = async () => {
return 0
}
Expand All @@ -34,6 +45,8 @@ file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Functio
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const d = async () => {
return ""
}
Expand All @@ -42,6 +55,8 @@ file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Functio
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const f = (p) => {}

// Error (good)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/a.js(7,15): error TS1005: '{' expected.
/a.js(10,27): error TS1005: '{' expected.


==== /a.js (2 errors) ====
/**
* @typedef {Object} T1
* @property {number} a
*/

/**
* @satisfies T1
~~
!!! error TS1005: '{' expected.
*/
const t1 = { a: 1 };
const t2 = /** @satisfies T1 */ ({ a: 1 });
~~
!!! error TS1005: '{' expected.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
0.js(12,13): error TS1110: Type expected.
0.js(20,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(24,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(24,21): error TS1005: '}' expected.
0.js(28,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(28,21): error TS1005: '}' expected.
0.js(40,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'props' must be of type 'object', but here has type 'Object'.


==== 0.js (4 errors) ====
==== 0.js (7 errors) ====
// @ts-check
/** @type {String} */
var S = "hello world";
Expand All @@ -17,6 +20,8 @@
anyT = "hello";

/** @type {?} */
~
!!! error TS1110: Type expected.
var anyT1 = 2;
anyT1 = "hi";

Expand All @@ -35,13 +40,17 @@
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x1 = (a) => a + 1;
x1(0);

/** @type {function (number): number} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x2 = (a) => a + 1;
x2(0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
0.js(3,5): error TS2322: Type 'boolean' is not assignable to type 'String'.
0.js(6,5): error TS2322: Type 'string' is not assignable to type 'number'.
0.js(8,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(8,21): error TS1005: '}' expected.
0.js(12,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(12,21): error TS1005: '}' expected.
0.js(19,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(19,21): error TS1005: '}' expected.
0.js(23,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(23,21): error TS1005: '}' expected.


==== 0.js (6 errors) ====
==== 0.js (10 errors) ====
// @ts-check
/** @type {String} */
var S = true;
Expand All @@ -22,13 +26,17 @@
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x1 = (a) => a + 1;
x1("string");

/** @type {function (number): number} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x2 = (a) => a + 1;

/** @type {string} */
Expand All @@ -39,12 +47,16 @@
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x3 = (a) => a.concat("hi");
x3(0);

/** @type {function (number): string} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
const x4 = (a) => a + 1;
x4(0);
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
0.js(8,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(8,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.
0.js(8,22): error TS1005: '}' expected.
0.js(16,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(16,22): error TS1005: '}' expected.


==== 0.js (3 errors) ====
==== 0.js (5 errors) ====
// @ts-check
var lol = "hello Lol"
const obj = {
Expand All @@ -17,6 +19,8 @@
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~~~~~~~~
!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.
~
!!! error TS1005: '}' expected.
method1(n1) {
return n1 + 42;
},
Expand All @@ -28,6 +32,8 @@
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
arrowFunc: (num) => num + 42
}
obj.foo = 'string'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
0.js(5,3): error TS2322: Type 'number' is not assignable to type 'string'.
0.js(6,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(6,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.
0.js(6,22): error TS1005: '}' expected.
0.js(10,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(10,22): error TS1005: '}' expected.
0.js(12,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
0.js(12,22): error TS1005: '}' expected.


==== 0.js (5 errors) ====
==== 0.js (8 errors) ====
// @ts-check
var lol;
const obj = {
Expand All @@ -19,18 +22,24 @@
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~~~~~~~~
!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.
~
!!! error TS1005: '}' expected.
method1(n1) {
return "42";
},
/** @type {function(number): number} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
method2: (n1) => "lol",
/** @type {function(number): number} */
~~~~~~~~
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
~
!!! error TS1005: '}' expected.
arrowFunc: (num="0") => num + 42,
/** @type {string} */
lol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
0.js(3,5): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
0.js(6,21): error TS1003: Identifier expected.
0.js(8,9): error TS2339: Property 'SomeName' does not exist on type '{}'.
0.js(10,12): error TS2503: Cannot find namespace 'exports'.


==== 0.js (3 errors) ====
==== 0.js (4 errors) ====
// @ts-check

var exports = {};
Expand All @@ -12,7 +13,10 @@

/**
* @typedef {string}

*/

!!! error TS1003: Identifier expected.
exports.SomeName;
~~~~~~~~
!!! error TS2339: Property 'SomeName' does not exist on type '{}'.
Expand Down
Loading