Skip to content

Commit

Permalink
Detect "Type X has no properties in common with type Y" in `expectErr…
Browse files Browse the repository at this point in the history
…or` (TS2559) (#97)
  • Loading branch information
sluukkonen committed May 25, 2021
1 parent b39bd98 commit 27c93af
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/lib/compiler.ts
Expand Up @@ -25,7 +25,8 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
DiagnosticCode.GenericTypeRequiresTypeArguments,
DiagnosticCode.ExpectedArgumentsButGotOther,
DiagnosticCode.NoOverloadMatches,
DiagnosticCode.PropertyMissingInType1ButRequiredInType2
DiagnosticCode.PropertyMissingInType1ButRequiredInType2,
DiagnosticCode.TypeHasNoPropertiesInCommonWith
]);

/**
Expand Down
1 change: 1 addition & 0 deletions source/lib/interfaces.ts
Expand Up @@ -29,6 +29,7 @@ export enum DiagnosticCode {
ArgumentTypeIsNotAssignableToParameterType = 2345,
CannotAssignToReadOnlyProperty = 2540,
ExpectedArgumentsButGotOther = 2554,
TypeHasNoPropertiesInCommonWith = 2559,
NoOverloadMatches = 2769,
PropertyMissingInType1ButRequiredInType2 = 2741,
}
Expand Down
4 changes: 4 additions & 0 deletions source/test/fixtures/expect-error/values/index.d.ts
Expand Up @@ -9,4 +9,8 @@ export const foo: {readonly bar: string};

export function hasProperty(property: {name: string}): boolean;

export type HasKey<K extends string, V = unknown> = {[P in K]?: V};

export function getFoo<T extends HasKey<'foo'>>(obj: T): T['foo'];

export interface Options<T> {}
4 changes: 3 additions & 1 deletion source/test/fixtures/expect-error/values/index.test-d.ts
@@ -1,5 +1,5 @@
import {expectError} from '../../../..';
import {default as one, foo, hasProperty, Options} from '.';
import {default as one, foo, getFoo, HasKey, hasProperty, Options} from '.';

expectError<string>(1);
expectError<string>('fo');
Expand All @@ -20,3 +20,5 @@ expectError(hasProperty({name: 1}));
expectError(one(1));
expectError(one(1, 2, 3));
expectError({} as Options);

expectError(getFoo({bar: 1} as HasKey<'bar'>));

0 comments on commit 27c93af

Please sign in to comment.