Merge pull request #17994 from Microsoft/allow-question-token-as-start-of-type
Allow question token as start of type
This commit is contained in:
commit
356f54af3d
8 changed files with 19 additions and 50 deletions
|
@ -2721,6 +2721,7 @@ namespace ts {
|
||||||
case SyntaxKind.FalseKeyword:
|
case SyntaxKind.FalseKeyword:
|
||||||
case SyntaxKind.ObjectKeyword:
|
case SyntaxKind.ObjectKeyword:
|
||||||
case SyntaxKind.AsteriskToken:
|
case SyntaxKind.AsteriskToken:
|
||||||
|
case SyntaxKind.QuestionToken:
|
||||||
return true;
|
return true;
|
||||||
case SyntaxKind.MinusToken:
|
case SyntaxKind.MinusToken:
|
||||||
return lookAhead(nextTokenIsNumericLiteral);
|
return lookAhead(nextTokenIsNumericLiteral);
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
tests/cases/conformance/jsdoc/0.js(5,4): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'.
|
|
||||||
tests/cases/conformance/jsdoc/0.js(12,1): error TS2322: Type 'number' is not assignable to type 'string'.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/jsdoc/0.js (2 errors) ====
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
/** @type {function (number)} */
|
|
||||||
const x1 = (a) => a + 1;
|
|
||||||
x1("string");
|
|
||||||
~~~~~~~~
|
|
||||||
!!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'.
|
|
||||||
|
|
||||||
/** @type {function (number): number} */
|
|
||||||
const x2 = (a) => a + 1;
|
|
||||||
|
|
||||||
/** @type {string} */
|
|
||||||
var a;
|
|
||||||
a = x2(0);
|
|
||||||
~
|
|
||||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
|
@ -1,24 +0,0 @@
|
||||||
//// [0.js]
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
/** @type {function (number)} */
|
|
||||||
const x1 = (a) => a + 1;
|
|
||||||
x1("string");
|
|
||||||
|
|
||||||
/** @type {function (number): number} */
|
|
||||||
const x2 = (a) => a + 1;
|
|
||||||
|
|
||||||
/** @type {string} */
|
|
||||||
var a;
|
|
||||||
a = x2(0);
|
|
||||||
|
|
||||||
//// [0.js]
|
|
||||||
// @ts-check
|
|
||||||
/** @type {function (number)} */
|
|
||||||
var x1 = function (a) { return a + 1; };
|
|
||||||
x1("string");
|
|
||||||
/** @type {function (number): number} */
|
|
||||||
var x2 = function (a) { return a + 1; };
|
|
||||||
/** @type {string} */
|
|
||||||
var a;
|
|
||||||
a = x2(0);
|
|
5
tests/baselines/reference/checkJsdocTypeTag3.symbols
Normal file
5
tests/baselines/reference/checkJsdocTypeTag3.symbols
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
=== tests/cases/conformance/jsdoc/test.js ===
|
||||||
|
/** @type {Array<?number>} */
|
||||||
|
var nns;
|
||||||
|
>nns : Symbol(nns, Decl(test.js, 1, 3))
|
||||||
|
|
5
tests/baselines/reference/checkJsdocTypeTag3.types
Normal file
5
tests/baselines/reference/checkJsdocTypeTag3.types
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
=== tests/cases/conformance/jsdoc/test.js ===
|
||||||
|
/** @type {Array<?number>} */
|
||||||
|
var nns;
|
||||||
|
>nns : number[]
|
||||||
|
|
|
@ -84,7 +84,6 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,20): e
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,23): error TS1003: Identifier expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,23): error TS1003: Identifier expected.
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,27): error TS1005: ',' expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,27): error TS1005: ',' expected.
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,23): error TS1005: ',' expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,23): error TS1005: ',' expected.
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,24): error TS1138: Parameter declaration expected.
|
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,28): error TS1003: Identifier expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,28): error TS1003: Identifier expected.
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,32): error TS1005: ',' expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,32): error TS1005: ',' expected.
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,30): error TS1005: ',' expected.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,30): error TS1005: ',' expected.
|
||||||
|
@ -94,7 +93,7 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,32): e
|
||||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,35): error TS2304: Cannot find name 'm'.
|
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,35): error TS2304: Cannot find name 'm'.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (60 errors) ====
|
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (59 errors) ====
|
||||||
class C {
|
class C {
|
||||||
n: number;
|
n: number;
|
||||||
explicitThis(this: this, m: number): number {
|
explicitThis(this: this, m: number): number {
|
||||||
|
@ -403,8 +402,6 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,35): e
|
||||||
function optional(this?: C): number { return this.n; }
|
function optional(this?: C): number { return this.n; }
|
||||||
~
|
~
|
||||||
!!! error TS1005: ',' expected.
|
!!! error TS1005: ',' expected.
|
||||||
~
|
|
||||||
!!! error TS1138: Parameter declaration expected.
|
|
||||||
function decorated(@deco() this: C): number { return this.n; }
|
function decorated(@deco() this: C): number { return this.n; }
|
||||||
~~~~
|
~~~~
|
||||||
!!! error TS1003: Identifier expected.
|
!!! error TS1003: Identifier expected.
|
||||||
|
|
|
@ -345,7 +345,7 @@ function modifiers(, C) {
|
||||||
return this.n;
|
return this.n;
|
||||||
}
|
}
|
||||||
function restParam(C) { return this.n; }
|
function restParam(C) { return this.n; }
|
||||||
function optional(C) { return this.n; }
|
function optional() { return this.n; }
|
||||||
function decorated(, C) {
|
function decorated(, C) {
|
||||||
if ( === void 0) { = this; }
|
if ( === void 0) { = this; }
|
||||||
return this.n;
|
return this.n;
|
||||||
|
|
6
tests/cases/conformance/jsdoc/checkJsdocTypeTag3.ts
Normal file
6
tests/cases/conformance/jsdoc/checkJsdocTypeTag3.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// @Filename:test.js
|
||||||
|
// @checkJs: true
|
||||||
|
// @allowJs: true
|
||||||
|
// @noEmit: true
|
||||||
|
/** @type {Array<?number>} */
|
||||||
|
var nns;
|
Loading…
Reference in a new issue