mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 02:21:30 -05:00
Remove unused error for this-type predicates.
Also: 1. Remove notes I wrote myself for merging. 2. Switch to pattern matching on properties in a few places.
This commit is contained in:
@@ -11138,29 +11138,19 @@ namespace ts {
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
// NEW we now get and check the return type -- is this needed?
|
||||
// Because of Wesley's change, sigs no longer have a special typePred member,
|
||||
// they have a type that extends PredicateType (with flags including PredicateType)
|
||||
const returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(parent));
|
||||
if (!returnType || !(returnType.flags & TypeFlags.PredicateType)) {
|
||||
return;
|
||||
}
|
||||
const { parameterName } = node;
|
||||
if (parameterName.kind === SyntaxKind.ThisType) {
|
||||
if (!isInLegalThisTypePredicatePosition(node)) {
|
||||
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(parameterName as ThisTypeNode);
|
||||
// TODO: Should probably skip past the other error checking now
|
||||
// ... because I bet the above function is the equivalent of this one.
|
||||
}
|
||||
getTypeFromThisTypeNode(parameterName as ThisTypeNode);
|
||||
}
|
||||
else {
|
||||
const typePredicate = <IdentifierTypePredicate>(<PredicateType>returnType).predicate;
|
||||
if (typePredicate.parameterIndex >= 0) {
|
||||
if (parent.parameters[typePredicate.parameterIndex].dotDotDotToken) {
|
||||
error(node.parameterName,
|
||||
error(parameterName,
|
||||
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
|
||||
}
|
||||
else {
|
||||
@@ -11169,14 +11159,14 @@ namespace ts {
|
||||
node.type);
|
||||
}
|
||||
}
|
||||
else if (node.parameterName) {
|
||||
else if (parameterName) {
|
||||
let hasReportedError = false;
|
||||
for (const param of parent.parameters) {
|
||||
if ((param.name.kind === SyntaxKind.ObjectBindingPattern ||
|
||||
param.name.kind === SyntaxKind.ArrayBindingPattern) &&
|
||||
for (const { name } of parent.parameters) {
|
||||
if ((name.kind === SyntaxKind.ObjectBindingPattern ||
|
||||
name.kind === SyntaxKind.ArrayBindingPattern) &&
|
||||
checkBindingPatternForTypePredicateVariable(
|
||||
<BindingPattern>param.name,
|
||||
node.parameterName,
|
||||
<BindingPattern>name,
|
||||
parameterName,
|
||||
typePredicate.parameterName)) {
|
||||
hasReportedError = true;
|
||||
break;
|
||||
@@ -11209,18 +11199,18 @@ namespace ts {
|
||||
pattern: BindingPattern,
|
||||
predicateVariableNode: Node,
|
||||
predicateVariableName: string) {
|
||||
for (const element of pattern.elements) {
|
||||
if (element.name.kind === SyntaxKind.Identifier &&
|
||||
(<Identifier>element.name).text === predicateVariableName) {
|
||||
for (const { name } of pattern.elements) {
|
||||
if (name.kind === SyntaxKind.Identifier &&
|
||||
(<Identifier>name).text === predicateVariableName) {
|
||||
error(predicateVariableNode,
|
||||
Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern,
|
||||
predicateVariableName);
|
||||
return true;
|
||||
}
|
||||
else if (element.name.kind === SyntaxKind.ArrayBindingPattern ||
|
||||
element.name.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
else if (name.kind === SyntaxKind.ArrayBindingPattern ||
|
||||
name.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
if (checkBindingPatternForTypePredicateVariable(
|
||||
<BindingPattern>element.name,
|
||||
<BindingPattern>name,
|
||||
predicateVariableNode,
|
||||
predicateVariableName)) {
|
||||
return true;
|
||||
@@ -11229,19 +11219,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isInLegalThisTypePredicatePosition(node: Node): boolean {
|
||||
if (getTypePredicateParent(node)) {
|
||||
return true;
|
||||
}
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.GetAccessor:
|
||||
return node === (node.parent as (PropertyDeclaration | GetAccessorDeclaration | PropertySignature)).type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkSignatureDeclaration(node: SignatureDeclaration) {
|
||||
// Grammar checking
|
||||
if (node.kind === SyntaxKind.IndexSignature) {
|
||||
|
||||
@@ -1651,10 +1651,6 @@
|
||||
"category": "Error",
|
||||
"code": 2518
|
||||
},
|
||||
"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
|
||||
},
|
||||
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
|
||||
"category": "Error",
|
||||
"code": 2520
|
||||
|
||||
Reference in New Issue
Block a user