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

Make expectError support TS2820 error introduced in TypeScript 4.5 #139

Merged
merged 1 commit into from
Dec 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions source/lib/compiler.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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';
})