Forbid non-null assertion in '.js' files (#17481)

This commit is contained in:
Andy
2017-07-28 16:40:20 -07:00
committed by GitHub
parent 58769e1dab
commit 2efaa7c9e2
5 changed files with 27 additions and 0 deletions

View File

@@ -16384,6 +16384,10 @@ namespace ts {
}
function checkNonNullAssertion(node: NonNullExpression) {
if (isInJavaScriptFile(node)) {
error(node, Diagnostics.non_null_assertions_can_only_be_used_in_a_ts_file);
}
return getNonNullableType(checkExpression(node.expression));
}

View File

@@ -3459,6 +3459,10 @@
"category": "Error",
"code": 8012
},
"'non-null assertions' can only be used in a .ts file.": {
"category": "Error",
"code": 8013
},
"'enum declarations' can only be used in a .ts file.": {
"category": "Error",
"code": 8015

View File

@@ -0,0 +1,8 @@
/src/a.js(1,1): error TS8013: 'non-null assertions' can only be used in a .ts file.
==== /src/a.js (1 errors) ====
0!
~~
!!! error TS8013: 'non-null assertions' can only be used in a .ts file.

View File

@@ -0,0 +1,6 @@
//// [a.js]
0!
//// [a.js]
0;

View File

@@ -0,0 +1,5 @@
// @allowJs: true
// @checkJs: true
// @filename: /src/a.js
// @out: /bin/a.js
0!