mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 15:25:54 -06:00
most pr feedback
This commit is contained in:
parent
dc765b8b5a
commit
028484664d
@ -5103,7 +5103,7 @@ namespace ts {
|
||||
const targetPredicate = target as PredicateType;
|
||||
if (sourcePredicate.predicate.kind !== targetPredicate.predicate.kind) {
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.A_this_based_type_guard_is_not_assignable_to_a_parameter_based_type_guard);
|
||||
reportError(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard);
|
||||
reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target));
|
||||
}
|
||||
return Ternary.False;
|
||||
@ -6506,10 +6506,7 @@ namespace ts {
|
||||
|
||||
function isAssignedInBinaryExpression(node: BinaryExpression) {
|
||||
if (node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment) {
|
||||
let n = node.left;
|
||||
while (n.kind === SyntaxKind.ParenthesizedExpression) {
|
||||
n = (<ParenthesizedExpression>n).expression;
|
||||
}
|
||||
const n = skipParenthesizedNodes(node.left);
|
||||
if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>n) === symbol) {
|
||||
return true;
|
||||
}
|
||||
@ -6844,13 +6841,6 @@ namespace ts {
|
||||
return type;
|
||||
}
|
||||
|
||||
function skipParenthesizedNodes(expression: Expression): Expression {
|
||||
while (expression.kind === SyntaxKind.ParenthesizedExpression) {
|
||||
expression = (expression as ParenthesizedExpression).expression;
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function getSymbolAtTypePredicatePosition(expr: Expression): Symbol {
|
||||
expr = skipParenthesizedNodes(expr);
|
||||
switch (expr.kind) {
|
||||
@ -6897,6 +6887,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function skipParenthesizedNodes(expression: Expression): Expression {
|
||||
while (expression.kind === SyntaxKind.ParenthesizedExpression) {
|
||||
expression = (expression as ParenthesizedExpression).expression;
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function checkIdentifier(node: Identifier): Type {
|
||||
const symbol = getResolvedSymbol(node);
|
||||
|
||||
@ -11085,7 +11082,7 @@ namespace ts {
|
||||
return -1;
|
||||
}
|
||||
|
||||
function isInLegalTypePredicatePosition(node: Node): boolean {
|
||||
function isInLegalParameterTypePredicatePosition(node: Node): boolean {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.CallSignature:
|
||||
@ -11100,7 +11097,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isInLegalThisTypePredicatePosition(node: Node): boolean {
|
||||
if (isInLegalTypePredicatePosition(node)) {
|
||||
if (isInLegalParameterTypePredicatePosition(node)) {
|
||||
return true;
|
||||
}
|
||||
switch (node.parent.kind) {
|
||||
@ -14332,12 +14329,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkTypePredicate(node: TypePredicateNode) {
|
||||
if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalTypePredicatePosition(node)) {
|
||||
if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalParameterTypePredicatePosition(node)) {
|
||||
error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
|
||||
}
|
||||
else if (node.parameterName.kind === SyntaxKind.ThisType) {
|
||||
if (!isInLegalThisTypePredicatePosition(node)) {
|
||||
error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_in_class_or_interface_members_get_accessors_or_return_type_positions_for_functions_and_methods);
|
||||
error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_within_a_class_or_interface_s_members_get_accessors_or_return_type_positions_for_functions_and_methods);
|
||||
}
|
||||
else {
|
||||
getTypeFromThisTypeNode(node.parameterName as ThisTypeNode);
|
||||
|
||||
@ -1647,11 +1647,11 @@
|
||||
"category": "Error",
|
||||
"code": 2517
|
||||
},
|
||||
"A 'this'-based type guard is not assignable to a parameter-based type guard": {
|
||||
"A 'this'-based type guard is not compatible with a parameter-based type guard.": {
|
||||
"category": "Error",
|
||||
"code": 2518
|
||||
},
|
||||
"A 'this'-based type predicate is only allowed in class or interface members, get accessors, or return type positions for functions and methods": {
|
||||
"A 'this'-based type predicate is only allowed within a class or interface's members, get accessors, or return type positions for functions and methods.": {
|
||||
"category": "Error",
|
||||
"code": 2519
|
||||
},
|
||||
|
||||
@ -2110,7 +2110,7 @@ namespace ts {
|
||||
ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6
|
||||
ThisType = 0x02000000, // This type
|
||||
ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties
|
||||
PredicateType = 0x08000000,
|
||||
PredicateType = 0x08000000, // Predicate types are also Boolean types, but should not be considered Intrinsics - there's no way to capture this with flags
|
||||
|
||||
/* @internal */
|
||||
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user