Separate error messages for 'null', 'undefined', or both.

This commit is contained in:
Anders Hejlsberg
2016-04-01 09:53:44 -07:00
parent ce81ba5156
commit 354fd10a2e
2 changed files with 17 additions and 3 deletions

View File

@@ -9554,8 +9554,14 @@ namespace ts {
function checkNonNullExpression(node: Expression | QualifiedName) {
const type = checkExpression(node);
if (strictNullChecks && getNullableKind(type)) {
error(node, Diagnostics.Object_is_possibly_null_or_undefined);
if (strictNullChecks) {
const kind = getNullableKind(type);
if (kind) {
error(node, kind & TypeFlags.Undefined ? kind & TypeFlags.Null ?
Diagnostics.Object_is_possibly_null_or_undefined :
Diagnostics.Object_is_possibly_undefined :
Diagnostics.Object_is_possibly_null);
}
return getNonNullableType(type);
}
return type;

View File

@@ -1727,10 +1727,18 @@
"category": "Error",
"code": 2530
},
"Object is possibly 'null' or 'undefined'.": {
"Object is possibly 'null'.": {
"category": "Error",
"code": 2531
},
"Object is possibly 'undefined'.": {
"category": "Error",
"code": 2532
},
"Object is possibly 'null' or 'undefined'.": {
"category": "Error",
"code": 2533
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600