Skip to content

Commit 8fe3924

Browse files
Allow expectError directives to detect parameter count mismatches (#102)
1 parent 27ccc49 commit 8fe3924

File tree

8 files changed

+34
-2
lines changed

8 files changed

+34
-2
lines changed

source/lib/compiler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
2424
DiagnosticCode.TypeDoesNotSatisfyTheConstraint,
2525
DiagnosticCode.GenericTypeRequiresTypeArguments,
2626
DiagnosticCode.ExpectedArgumentsButGotOther,
27+
DiagnosticCode.NoOverloadExpectsCountOfArguments,
28+
DiagnosticCode.NoOverloadExpectsCountOfTypeArguments,
2729
DiagnosticCode.NoOverloadMatches,
2830
DiagnosticCode.PropertyMissingInType1ButRequiredInType2,
2931
DiagnosticCode.TypeHasNoPropertiesInCommonWith,

source/lib/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export enum DiagnosticCode {
3434
ExpressionNotCallable = 2349,
3535
OnlyVoidFunctionIsNewCallable = 2350,
3636
ExpressionNotConstructable = 2351,
37+
NoOverloadExpectsCountOfArguments = 2575,
3738
ThisContextOfTypeNotAssignableToMethodOfThisType = 2684,
3839
PropertyMissingInType1ButRequiredInType2 = 2741,
40+
NoOverloadExpectsCountOfTypeArguments = 2743,
3941
NoOverloadMatches = 2769,
4042
NewExpressionTargetLackingConstructSignatureHasAnyType = 7009,
4143
}

source/test/fixtures/expect-error/functions/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ declare const one: {
66

77
export default one;
88

9+
export const two: {
10+
(foo: string): string;
11+
(foo: string, bar: string, baz: string): string;
12+
};
13+
914
export const three: {
1015
(foo: '*'): string;
1116
(foo: 'a' | 'b'): string;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports.default = (foo, bar) => foo + bar;
22

3+
module.exports.two = (foo, bar, baz) => {
4+
if (foo!= null && bar != null && baz != null) {
5+
return foo + bar + baz;
6+
} else {
7+
return foo;
8+
}
9+
};
10+
311
exports.three = (foo) => 'a';
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {expectError} from '../../../..';
2-
import one, {three} from '.';
2+
import one, {two, three} from '.';
33

44
expectError(one(true, true));
55
expectError(one('foo', 'bar'));
66

7+
expectError(two('foo', 'bar'));
8+
79
// Produces multiple type checker errors in a single `expectError` assertion
810
expectError(three(['a', 'bad']));

source/test/fixtures/expect-error/generics/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ declare const one: {
33
};
44

55
export default one;
6+
7+
export function two<T1>(foo: T1): T1;
8+
export function two<T1, T2, T3 extends T2>(foo: T1, bar: T2): T3;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports.default = (foo, bar) => {
22
return foo + bar;
33
};
4+
5+
exports.two = (foo, bar) => {
6+
if (foo != null && bar != null) {
7+
return bar;
8+
} else {
9+
return foo;
10+
}
11+
};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {expectError} from '../../../..';
2-
import one from '.';
2+
import one, {two} from '.';
33

44
expectError(one(true, true));
55

66
expectError(one<number>(1, 2));
7+
8+
expectError(two<number, string>(1, 'bar'));

0 commit comments

Comments
 (0)