Skip to content

Commit

Permalink
Allow expectError directives to detect parameter count mismatches (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender committed May 28, 2021
1 parent 27ccc49 commit 8fe3924
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions source/lib/compiler.ts
Expand Up @@ -24,6 +24,8 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
DiagnosticCode.TypeDoesNotSatisfyTheConstraint,
DiagnosticCode.GenericTypeRequiresTypeArguments,
DiagnosticCode.ExpectedArgumentsButGotOther,
DiagnosticCode.NoOverloadExpectsCountOfArguments,
DiagnosticCode.NoOverloadExpectsCountOfTypeArguments,
DiagnosticCode.NoOverloadMatches,
DiagnosticCode.PropertyMissingInType1ButRequiredInType2,
DiagnosticCode.TypeHasNoPropertiesInCommonWith,
Expand Down
2 changes: 2 additions & 0 deletions source/lib/interfaces.ts
Expand Up @@ -34,8 +34,10 @@ export enum DiagnosticCode {
ExpressionNotCallable = 2349,
OnlyVoidFunctionIsNewCallable = 2350,
ExpressionNotConstructable = 2351,
NoOverloadExpectsCountOfArguments = 2575,
ThisContextOfTypeNotAssignableToMethodOfThisType = 2684,
PropertyMissingInType1ButRequiredInType2 = 2741,
NoOverloadExpectsCountOfTypeArguments = 2743,
NoOverloadMatches = 2769,
NewExpressionTargetLackingConstructSignatureHasAnyType = 7009,
}
Expand Down
5 changes: 5 additions & 0 deletions source/test/fixtures/expect-error/functions/index.d.ts
Expand Up @@ -6,6 +6,11 @@ declare const one: {

export default one;

export const two: {
(foo: string): string;
(foo: string, bar: string, baz: string): string;
};

export const three: {
(foo: '*'): string;
(foo: 'a' | 'b'): string;
Expand Down
8 changes: 8 additions & 0 deletions source/test/fixtures/expect-error/functions/index.js
@@ -1,3 +1,11 @@
module.exports.default = (foo, bar) => foo + bar;

module.exports.two = (foo, bar, baz) => {
if (foo!= null && bar != null && baz != null) {
return foo + bar + baz;
} else {
return foo;
}
};

exports.three = (foo) => 'a';
4 changes: 3 additions & 1 deletion source/test/fixtures/expect-error/functions/index.test-d.ts
@@ -1,8 +1,10 @@
import {expectError} from '../../../..';
import one, {three} from '.';
import one, {two, three} from '.';

expectError(one(true, true));
expectError(one('foo', 'bar'));

expectError(two('foo', 'bar'));

// Produces multiple type checker errors in a single `expectError` assertion
expectError(three(['a', 'bad']));
3 changes: 3 additions & 0 deletions source/test/fixtures/expect-error/generics/index.d.ts
Expand Up @@ -3,3 +3,6 @@ declare const one: {
};

export default one;

export function two<T1>(foo: T1): T1;
export function two<T1, T2, T3 extends T2>(foo: T1, bar: T2): T3;
8 changes: 8 additions & 0 deletions source/test/fixtures/expect-error/generics/index.js
@@ -1,3 +1,11 @@
module.exports.default = (foo, bar) => {
return foo + bar;
};

exports.two = (foo, bar) => {
if (foo != null && bar != null) {
return bar;
} else {
return foo;
}
};
4 changes: 3 additions & 1 deletion source/test/fixtures/expect-error/generics/index.test-d.ts
@@ -1,6 +1,8 @@
import {expectError} from '../../../..';
import one from '.';
import one, {two} from '.';

expectError(one(true, true));

expectError(one<number>(1, 2));

expectError(two<number, string>(1, 'bar'));

0 comments on commit 8fe3924

Please sign in to comment.