aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/unifiedSignaturesRule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/rules/unifiedSignaturesRule.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/tslint/lib/rules/unifiedSignaturesRule.js')
-rw-r--r--node_modules/tslint/lib/rules/unifiedSignaturesRule.js30
1 files changed, 16 insertions, 14 deletions
diff --git a/node_modules/tslint/lib/rules/unifiedSignaturesRule.js b/node_modules/tslint/lib/rules/unifiedSignaturesRule.js
index 578dae231..771ef1604 100644
--- a/node_modules/tslint/lib/rules/unifiedSignaturesRule.js
+++ b/node_modules/tslint/lib/rules/unifiedSignaturesRule.js
@@ -45,18 +45,18 @@ var Rule = (function (_super) {
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "unified-signatures",
+ description: "Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.",
+ optionsDescription: "Not configurable.",
+ options: null,
+ optionExamples: [true],
+ type: "typescript",
+ typescriptOnly: true,
+ };
return Rule;
}(Lint.Rules.AbstractRule));
-/* tslint:disable:object-literal-sort-keys */
-Rule.metadata = {
- ruleName: "unified-signatures",
- description: "Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.",
- optionsDescription: "Not configurable.",
- options: null,
- optionExamples: [true],
- type: "typescript",
- typescriptOnly: true,
-};
exports.Rule = Rule;
function walk(ctx) {
var sourceFile = ctx.sourceFile;
@@ -74,7 +74,6 @@ function walk(ctx) {
}
case ts.SyntaxKind.TypeLiteral:
checkMembers(node.members);
- break;
}
return ts.forEachChild(node, cb);
});
@@ -127,7 +126,6 @@ function walk(ctx) {
ctx.addFailureAtNode(extraParameter, extraParameter.dotDotDotToken !== undefined
? Rule.FAILURE_STRING_OMITTING_REST_PARAMETER(lineOfOtherOverload)
: Rule.FAILURE_STRING_OMITTING_SINGLE_PARAMETER(lineOfOtherOverload));
- break;
}
}
}
@@ -186,7 +184,11 @@ function signaturesDifferBySingleParameter(types1, types2) {
}
var a = types1[index];
var b = types2[index];
- return parametersHaveEqualSigils(a, b) ? { kind: "single-parameter-difference", p0: a, p1: b } : undefined;
+ // Can unify `a?: string` and `b?: number`. Can't unify `...args: string[]` and `...args: number[]`.
+ // See https://github.com/Microsoft/TypeScript/issues/5077
+ return parametersHaveEqualSigils(a, b) && a.dotDotDotToken === undefined
+ ? { kind: "single-parameter-difference", p0: a, p1: b }
+ : undefined;
}
/**
* Detect `a(): void` and `a(x: number): void`.
@@ -228,7 +230,7 @@ function getIsTypeParameter(typeParameters) {
}
/** True if any of the outer type parameters are used in a signature. */
function signatureUsesTypeParameter(sig, isTypeParameter) {
- return sig.parameters.some(function (p) { return p.type !== undefined && typeContainsTypeParameter(p.type); });
+ return sig.parameters.some(function (p) { return p.type !== undefined && typeContainsTypeParameter(p.type) === true; });
function typeContainsTypeParameter(type) {
if (utils.isTypeReferenceNode(type)) {
var typeName = type.typeName;