Skip to content

Commit 1c6bcfb

Browse files
BendingBenderSamVerschueren
authored andcommittedMar 19, 2019
Ignore more diagnostics with expectError (#17)
1 parent c11bbb8 commit 1c6bcfb

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
 

‎source/lib/compiler.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ const extractExpectErrorRanges = (sourceFile: SourceFile) => {
6969
return expectedErrors;
7070
};
7171

72+
const diagnosticCodesToIgnore = [
73+
DiagnosticCode.ArgumentTypeIsNotAssignableToParameterType,
74+
DiagnosticCode.PropertyDoesNotExistOnType,
75+
DiagnosticCode.CannotAssignToReadOnlyProperty
76+
];
77+
7278
/**
7379
* Check if the provided diagnostic should be ignored.
7480
*
@@ -82,7 +88,7 @@ const ignoreDiagnostic = (diagnostic: TSDiagnostic, expectedErrors: Map<Position
8288
return true;
8389
}
8490

85-
if (diagnostic.code !== DiagnosticCode.ArgumentTypeIsNotAssignableToParameterType) {
91+
if (!diagnosticCodesToIgnore.includes(diagnostic.code)) {
8692
return false;
8793
}
8894

‎source/lib/interfaces.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export interface Context {
77

88
export enum DiagnosticCode {
99
AwaitIsOnlyAllowedInAsyncFunction = 1308,
10-
ArgumentTypeIsNotAssignableToParameterType = 2345
10+
PropertyDoesNotExistOnType = 2339,
11+
ArgumentTypeIsNotAssignableToParameterType = 2345,
12+
CannotAssignToReadOnlyProperty = 2540
1113
}
1214

1315
export interface Diagnostic {

‎source/test/fixtures/expect-error/values/index.test-d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ import {expectError} from '../../../..';
22

33
expectError<string>(1);
44
expectError<string>('fo');
5+
6+
const foo: {readonly bar: string} = {
7+
bar: 'baz'
8+
};
9+
10+
expectError(foo.bar = 'quux');
11+
expectError(foo.quux);

0 commit comments

Comments
 (0)
Please sign in to comment.