Skip to content

Commit 27c93af

Browse files
authored
Detect "Type X has no properties in common with type Y" in expectError (TS2559) (#97)
1 parent b39bd98 commit 27c93af

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

source/lib/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const expectErrordiagnosticCodesToIgnore = new Set<DiagnosticCode>([
2525
DiagnosticCode.GenericTypeRequiresTypeArguments,
2626
DiagnosticCode.ExpectedArgumentsButGotOther,
2727
DiagnosticCode.NoOverloadMatches,
28-
DiagnosticCode.PropertyMissingInType1ButRequiredInType2
28+
DiagnosticCode.PropertyMissingInType1ButRequiredInType2,
29+
DiagnosticCode.TypeHasNoPropertiesInCommonWith
2930
]);
3031

3132
/**

source/lib/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum DiagnosticCode {
2929
ArgumentTypeIsNotAssignableToParameterType = 2345,
3030
CannotAssignToReadOnlyProperty = 2540,
3131
ExpectedArgumentsButGotOther = 2554,
32+
TypeHasNoPropertiesInCommonWith = 2559,
3233
NoOverloadMatches = 2769,
3334
PropertyMissingInType1ButRequiredInType2 = 2741,
3435
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ export const foo: {readonly bar: string};
99

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

12+
export type HasKey<K extends string, V = unknown> = {[P in K]?: V};
13+
14+
export function getFoo<T extends HasKey<'foo'>>(obj: T): T['foo'];
15+
1216
export interface Options<T> {}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectError} from '../../../..';
2-
import {default as one, foo, hasProperty, Options} from '.';
2+
import {default as one, foo, getFoo, HasKey, hasProperty, Options} from '.';
33

44
expectError<string>(1);
55
expectError<string>('fo');
@@ -20,3 +20,5 @@ expectError(hasProperty({name: 1}));
2020
expectError(one(1));
2121
expectError(one(1, 2, 3));
2222
expectError({} as Options);
23+
24+
expectError(getFoo({bar: 1} as HasKey<'bar'>));

0 commit comments

Comments
 (0)