Skip to content

Commit

Permalink
Make expectError support TS2820 error introduced in TypeScript 4.5 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Dec 29, 2021
1 parent 5347e25 commit b231b70
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/lib/compiler.ts
Expand Up @@ -37,6 +37,7 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
DiagnosticCode.NewExpressionTargetLackingConstructSignatureHasAnyType,
DiagnosticCode.MemberCannotHaveOverrideModifierBecauseItIsNotDeclaredInBaseClass,
DiagnosticCode.MemberMustHaveOverrideModifier,
DiagnosticCode.StringLiteralTypeIsNotAssignableToUnionTypeWithSuggestion,
]);

type IgnoreDiagnosticResult = 'preserve' | 'ignore' | Location;
Expand Down
1 change: 1 addition & 0 deletions source/lib/interfaces.ts
Expand Up @@ -43,6 +43,7 @@ export enum DiagnosticCode {
PropertyMissingInType1ButRequiredInType2 = 2741,
NoOverloadExpectsCountOfTypeArguments = 2743,
NoOverloadMatches = 2769,
StringLiteralTypeIsNotAssignableToUnionTypeWithSuggestion = 2820,
MemberCannotHaveOverrideModifierBecauseItIsNotDeclaredInBaseClass = 4113,
MemberMustHaveOverrideModifier = 4114,
NewExpressionTargetLackingConstructSignatureHasAnyType = 7009,
Expand Down
6 changes: 6 additions & 0 deletions source/test/fixtures/expect-error/values/index.d.ts
Expand Up @@ -18,3 +18,9 @@ export function atLeastOne(...expected: [unknown, ...Array<unknown>]): void;
export interface Options<T> {}

export class MyClass {}

export const triggerSuggestion: {
// fooOrBar must be of union type to trigger TS2820, otherwise TypeScript will
// emit a regular TS2322 error without the "Did you mean..." suggestion.
fooOrBar: 'foo' | 'bar';
};
6 changes: 5 additions & 1 deletion source/test/fixtures/expect-error/values/index.test-d.ts
@@ -1,5 +1,5 @@
import {expectError} from '../../../..';
import {default as one, atLeastOne, foo, getFoo, HasKey, hasProperty, MyClass, Options} from '.';
import {default as one, atLeastOne, foo, getFoo, HasKey, hasProperty, MyClass, Options, triggerSuggestion} from '.';

expectError<string>(1);
expectError<string>('fo');
Expand Down Expand Up @@ -33,3 +33,7 @@ expectError(MyClass());

// 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
expectError(new hasProperty({name: 'foo'}));

expectError(() => {
triggerSuggestion.fooOrBar = 'fooo';
})

0 comments on commit b231b70

Please sign in to comment.