Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow expectError directives to detect parameter count mismatches #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/lib/compiler.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'));