Skip to content

Commit ec4ea87

Browse files
Add support for generics in expectError assertion - fixes #64
1 parent f988ee1 commit ec4ea87

File tree

8 files changed

+27
-1
lines changed

8 files changed

+27
-1
lines changed

source/lib/compiler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
2121
DiagnosticCode.PropertyDoesNotExistOnType,
2222
DiagnosticCode.CannotAssignToReadOnlyProperty,
2323
DiagnosticCode.TypeIsNotAssignableToOtherType,
24+
DiagnosticCode.TypeDoesNotSatisfyTheConstraint,
2425
DiagnosticCode.GenericTypeRequiresTypeArguments,
2526
DiagnosticCode.ExpectedArgumentsButGotOther,
2627
DiagnosticCode.NoOverloadMatches,

source/lib/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ export enum DiagnosticCode {
2323
TopLevelAwaitOnlyAllowedWhenModuleESNextOrSystem = 1378,
2424
GenericTypeRequiresTypeArguments = 2314,
2525
TypeIsNotAssignableToOtherType = 2322,
26+
TypeDoesNotSatisfyTheConstraint = 2344,
2627
PropertyDoesNotExistOnType = 2339,
2728
ArgumentTypeIsNotAssignableToParameterType = 2345,
2829
CannotAssignToReadOnlyProperty = 2540,
2930
ExpectedArgumentsButGotOther = 2554,
3031
NoOverloadMatches = 2769,
31-
PropertyMissingInType1ButRequiredInType2 = 2741
32+
PropertyMissingInType1ButRequiredInType2 = 2741,
3233
}
3334

3435
export interface Diagnostic {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
declare const one: {
22
(foo: string, bar: string): string;
33
(foo: number, bar: number): number;
4+
<T extends string>(foo: T, bar: T): string;
45
};
56

67
export default one;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare const one: {
2+
<T extends string>(foo: T, bar: T): T;
3+
};
4+
5+
export default one;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.default = (foo, bar) => {
2+
return foo + bar;
3+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {expectError} from '../../../..';
2+
import one from '.';
3+
4+
expectError(one(true, true));
5+
6+
expectError(one<number>(1, 2));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "foo"
3+
}

source/test/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ test('expectError for functions', async t => {
175175
]);
176176
});
177177

178+
test('expectError for generics', async t => {
179+
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/generics')});
180+
181+
verify(t, diagnostics, []);
182+
});
183+
178184
test('expectError should not ignore syntactical errors', async t => {
179185
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/syntax')});
180186

0 commit comments

Comments
 (0)