mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 07:55:10 -05:00
Js/check type tags (#24967)
* Check the type expression of `@type` tags * Update existing tests and baselines
This commit is contained in:
committed by
GitHub
parent
34b9c4dbad
commit
57e652dd02
@@ -22601,6 +22601,10 @@ namespace ts {
|
||||
checkSourceElement(node.typeExpression);
|
||||
}
|
||||
|
||||
function checkJSDocTypeTag(node: JSDocTypeTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
}
|
||||
|
||||
function checkJSDocParameterTag(node: JSDocParameterTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
if (!getParameterSymbolFromJSDoc(node)) {
|
||||
@@ -25562,6 +25566,8 @@ namespace ts {
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
case SyntaxKind.JSDocCallbackTag:
|
||||
return checkJSDocTypeAliasTag(node as JSDocTypedefTag);
|
||||
case SyntaxKind.JSDocTypeTag:
|
||||
return checkJSDocTypeTag(node as JSDocTypeTag);
|
||||
case SyntaxKind.JSDocParameterTag:
|
||||
return checkJSDocParameterTag(node as JSDocParameterTag);
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
|
||||
21
tests/baselines/reference/checkJsdocTypeTag4.errors.txt
Normal file
21
tests/baselines/reference/checkJsdocTypeTag4.errors.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
tests/cases/conformance/jsdoc/test.js(5,14): error TS2344: Type 'number' does not satisfy the constraint 'string'.
|
||||
tests/cases/conformance/jsdoc/test.js(7,14): error TS2344: Type 'number' does not satisfy the constraint 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/t.d.ts (0 errors) ====
|
||||
type A<T extends string> = { a: T }
|
||||
|
||||
==== tests/cases/conformance/jsdoc/test.js (2 errors) ====
|
||||
/** Also should error for jsdoc typedefs
|
||||
* @template {string} U
|
||||
* @typedef {{ b: U }} B
|
||||
*/
|
||||
/** @type {A<number>} */
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
|
||||
var a;
|
||||
/** @type {B<number>} */
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
|
||||
var b;
|
||||
|
||||
20
tests/baselines/reference/checkJsdocTypeTag4.symbols
Normal file
20
tests/baselines/reference/checkJsdocTypeTag4.symbols
Normal file
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/jsdoc/t.d.ts ===
|
||||
type A<T extends string> = { a: T }
|
||||
>A : Symbol(A, Decl(t.d.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(t.d.ts, 0, 7))
|
||||
>a : Symbol(a, Decl(t.d.ts, 0, 28))
|
||||
>T : Symbol(T, Decl(t.d.ts, 0, 7))
|
||||
|
||||
=== tests/cases/conformance/jsdoc/test.js ===
|
||||
/** Also should error for jsdoc typedefs
|
||||
* @template {string} U
|
||||
* @typedef {{ b: U }} B
|
||||
*/
|
||||
/** @type {A<number>} */
|
||||
var a;
|
||||
>a : Symbol(a, Decl(test.js, 5, 3))
|
||||
|
||||
/** @type {B<number>} */
|
||||
var b;
|
||||
>b : Symbol(b, Decl(test.js, 7, 3))
|
||||
|
||||
20
tests/baselines/reference/checkJsdocTypeTag4.types
Normal file
20
tests/baselines/reference/checkJsdocTypeTag4.types
Normal file
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/jsdoc/t.d.ts ===
|
||||
type A<T extends string> = { a: T }
|
||||
>A : A<T>
|
||||
>T : T
|
||||
>a : T
|
||||
>T : T
|
||||
|
||||
=== tests/cases/conformance/jsdoc/test.js ===
|
||||
/** Also should error for jsdoc typedefs
|
||||
* @template {string} U
|
||||
* @typedef {{ b: U }} B
|
||||
*/
|
||||
/** @type {A<number>} */
|
||||
var a;
|
||||
>a : A<number>
|
||||
|
||||
/** @type {B<number>} */
|
||||
var b;
|
||||
>b : { b: number; }
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
tests/cases/compiler/example.js(3,20): error TS1110: Type expected.
|
||||
tests/cases/compiler/example.js(3,21): error TS2304: Cannot find name 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/example.js (1 errors) ====
|
||||
==== tests/cases/compiler/example.js (2 errors) ====
|
||||
// @ts-check
|
||||
/**
|
||||
* @type {function(@foo)}
|
||||
~
|
||||
!!! error TS1110: Type expected.
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
*/
|
||||
let x;
|
||||
@@ -1,9 +1,11 @@
|
||||
tests/cases/conformance/jsdoc/a.js(16,12): error TS2314: Generic type 'Everything' requires 5 type argument(s).
|
||||
tests/cases/conformance/jsdoc/a.js(12,23): error TS2344: Type '{ a: number; }' does not satisfy the constraint '{ a: number; b: string; }'.
|
||||
Property 'b' is missing in type '{ a: number; }'.
|
||||
tests/cases/conformance/jsdoc/a.js(15,12): error TS2314: Generic type 'Everything' requires 5 type argument(s).
|
||||
tests/cases/conformance/jsdoc/test.ts(1,34): error TS2344: Type '{ a: number; }' does not satisfy the constraint '{ a: number; b: string; }'.
|
||||
Property 'b' is missing in type '{ a: number; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/a.js (1 errors) ====
|
||||
==== tests/cases/conformance/jsdoc/a.js (2 errors) ====
|
||||
/**
|
||||
* @template {{ a: number, b: string }} T,U A Comment
|
||||
* @template {{ c: boolean }} V uh ... are comments even supported??
|
||||
@@ -15,8 +17,10 @@ tests/cases/conformance/jsdoc/test.ts(1,34): error TS2344: Type '{ a: number; }'
|
||||
/** @type {Everything<{ a: number, b: 'hi', c: never }, undefined, { c: true, d: 1 }, number, string>} */
|
||||
var tuvwx;
|
||||
|
||||
// TODO: will error when #24592 is fixed
|
||||
/** @type {Everything<{ a: number }, undefined, { c: 1, d: 1 }, number, string>} */
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2344: Type '{ a: number; }' does not satisfy the constraint '{ a: number; b: string; }'.
|
||||
!!! error TS2344: Property 'b' is missing in type '{ a: number; }'.
|
||||
var wrong;
|
||||
|
||||
/** @type {Everything<{ a: number }>} */
|
||||
|
||||
@@ -11,14 +11,13 @@
|
||||
var tuvwx;
|
||||
>tuvwx : Symbol(tuvwx, Decl(a.js, 9, 3))
|
||||
|
||||
// TODO: will error when #24592 is fixed
|
||||
/** @type {Everything<{ a: number }, undefined, { c: 1, d: 1 }, number, string>} */
|
||||
var wrong;
|
||||
>wrong : Symbol(wrong, Decl(a.js, 13, 3))
|
||||
>wrong : Symbol(wrong, Decl(a.js, 12, 3))
|
||||
|
||||
/** @type {Everything<{ a: number }>} */
|
||||
var insufficient;
|
||||
>insufficient : Symbol(insufficient, Decl(a.js, 16, 3))
|
||||
>insufficient : Symbol(insufficient, Decl(a.js, 15, 3))
|
||||
|
||||
=== tests/cases/conformance/jsdoc/test.ts ===
|
||||
declare var actually: Everything<{ a: number }, undefined, { c: 1, d: 1 }, number, string>;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
var tuvwx;
|
||||
>tuvwx : { t: { a: number; b: "hi"; c: never; }; u: undefined; v: { c: true; d: 1; }; w: number; x: string; }
|
||||
|
||||
// TODO: will error when #24592 is fixed
|
||||
/** @type {Everything<{ a: number }, undefined, { c: 1, d: 1 }, number, string>} */
|
||||
var wrong;
|
||||
>wrong : { t: { a: number; }; u: undefined; v: { c: 1; d: 1; }; w: number; x: string; }
|
||||
|
||||
16
tests/cases/conformance/jsdoc/checkJsdocTypeTag4.ts
Normal file
16
tests/cases/conformance/jsdoc/checkJsdocTypeTag4.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// @checkJs: true
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @Filename: t.d.ts
|
||||
type A<T extends string> = { a: T }
|
||||
|
||||
// @Filename: test.js
|
||||
/** Also should error for jsdoc typedefs
|
||||
* @template {string} U
|
||||
* @typedef {{ b: U }} B
|
||||
*/
|
||||
/** @type {A<number>} */
|
||||
var a;
|
||||
/** @type {B<number>} */
|
||||
var b;
|
||||
@@ -13,7 +13,6 @@
|
||||
/** @type {Everything<{ a: number, b: 'hi', c: never }, undefined, { c: true, d: 1 }, number, string>} */
|
||||
var tuvwx;
|
||||
|
||||
// TODO: will error when #24592 is fixed
|
||||
/** @type {Everything<{ a: number }, undefined, { c: 1, d: 1 }, number, string>} */
|
||||
var wrong;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user