Skip to content

Commit 76955ce

Browse files
author
Andy Hanson
committed
Expand tests that jsdoc does not affect typescript code
1 parent dc40f5d commit 76955ce

File tree

5 files changed

+104
-38
lines changed

5 files changed

+104
-38
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
tests/cases/compiler/jsdocInTypeScript.ts(16,23): error TS2304: Cannot find name 'MyType'.
2+
tests/cases/compiler/jsdocInTypeScript.ts(23,33): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
3+
tests/cases/compiler/jsdocInTypeScript.ts(25,3): error TS2345: Argument of type '1' is not assignable to parameter of type 'boolean'.
4+
tests/cases/compiler/jsdocInTypeScript.ts(25,15): error TS2339: Property 'length' does not exist on type 'number'.
5+
tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does not exist on type '{}'.
6+
7+
8+
==== tests/cases/compiler/jsdocInTypeScript.ts (5 errors) ====
9+
// JSDoc typedef tags are not bound TypeScript files.
10+
/** @typedef {function} T */
11+
declare const x: T;
12+
13+
class T {
14+
prop: number;
15+
}
16+
17+
x.prop;
18+
19+
// Just to be sure that @property has no impact either.
20+
/**
21+
* @typedef {Object} MyType
22+
* @property {string} yes
23+
*/
24+
declare const myType: MyType; // should error, no such type
25+
~~~~~~
26+
!!! error TS2304: Cannot find name 'MyType'.
27+
28+
// @param type has no effect.
29+
/**
30+
* @param {number} x
31+
* @returns string
32+
*/
33+
function f(x: boolean) { return x * 2; } // Should error
34+
~
35+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
36+
// Should fail, because it takes a boolean and returns a number
37+
f(1); f(true).length;
38+
~
39+
!!! error TS2345: Argument of type '1' is not assignable to parameter of type 'boolean'.
40+
~~~~~~
41+
!!! error TS2339: Property 'length' does not exist on type 'number'.
42+
43+
// @type has no effect either.
44+
/** @type {{ x?: number }} */
45+
const z = {};
46+
z.x = 1;
47+
~
48+
!!! error TS2339: Property 'x' does not exist on type '{}'.
49+

tests/baselines/reference/jsdocInTypeScript.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ class T {
88
}
99

1010
x.prop;
11+
12+
// Just to be sure that @property has no impact either.
13+
/**
14+
* @typedef {Object} MyType
15+
* @property {string} yes
16+
*/
17+
declare const myType: MyType; // should error, no such type
18+
19+
// @param type has no effect.
20+
/**
21+
* @param {number} x
22+
* @returns string
23+
*/
24+
function f(x: boolean) { return x * 2; } // Should error
25+
// Should fail, because it takes a boolean and returns a number
26+
f(1); f(true).length;
27+
28+
// @type has no effect either.
29+
/** @type {{ x?: number }} */
30+
const z = {};
31+
z.x = 1;
1132

1233

1334
//// [jsdocInTypeScript.js]
@@ -17,3 +38,16 @@ var T = (function () {
1738
return T;
1839
}());
1940
x.prop;
41+
// @param type has no effect.
42+
/**
43+
* @param {number} x
44+
* @returns string
45+
*/
46+
function f(x) { return x * 2; } // Should error
47+
// Should fail, because it takes a boolean and returns a number
48+
f(1);
49+
f(true).length;
50+
// @type has no effect either.
51+
/** @type {{ x?: number }} */
52+
var z = {};
53+
z.x = 1;

tests/baselines/reference/jsdocInTypeScript.symbols

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/baselines/reference/jsdocInTypeScript.types

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/cases/compiler/jsdocInTypeScript.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,24 @@ class T {
77
}
88

99
x.prop;
10+
11+
// Just to be sure that @property has no impact either.
12+
/**
13+
* @typedef {Object} MyType
14+
* @property {string} yes
15+
*/
16+
declare const myType: MyType; // should error, no such type
17+
18+
// @param type has no effect.
19+
/**
20+
* @param {number} x
21+
* @returns string
22+
*/
23+
function f(x: boolean) { return x * 2; } // Should error
24+
// Should fail, because it takes a boolean and returns a number
25+
f(1); f(true).length;
26+
27+
// @type has no effect either.
28+
/** @type {{ x?: number }} */
29+
const z = {};
30+
z.x = 1;

0 commit comments

Comments
 (0)