Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7597,8 +7597,8 @@ namespace ts {
}
}
// The properties of a union type are those that are present in all constituent types, so
// we only need to check the properties of the first type
if (type.flags & TypeFlags.Union) {
// we only need to check the properties of the first type without index signature
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// we only need to check the properties of the first type wihtout index signature
// we only need to check the properties of the first type without index signature

if (type.flags & TypeFlags.Union && !getIndexInfoOfType(current, IndexKind.String) && !getIndexInfoOfType(current, IndexKind.Number)) {
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/conditionalTypes2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS23
Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
Type 'keyof B' is not assignable to type '"valueOf"'.
Type 'string | number | symbol' is not assignable to type '"valueOf"'.
Type 'string' is not assignable to type '"valueOf"'.
Type 'keyof B' is not assignable to type 'number'.
Type 'string | number | symbol' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
Types of property 'foo' are incompatible.
Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
Expand Down Expand Up @@ -77,9 +77,9 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
!!! error TS2322: Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
!!! error TS2322: Type 'keyof B' is not assignable to type '"valueOf"'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type '"valueOf"'.
!!! error TS2322: Type 'string' is not assignable to type '"valueOf"'.
!!! error TS2322: Type 'keyof B' is not assignable to type 'number'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
b = a; // Error
~
!!! error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
Expand Down
15 changes: 12 additions & 3 deletions tests/cases/fourslash/completionEntryForUnionProperty2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
////interface One {
//// commonProperty: string;
//// commonFunction(): number;
//// anotherProperty: Record<string, number>;
////}
////
////interface Two {
//// commonProperty: number;
//// commonFunction(): number;
//// anotherProperty: { foo: number }
////}
////
////var x : One | Two;
////
////x.commonProperty./**/
////x.commonProperty./*1*/;
////x.anotherProperty./*2*/;

verify.completions({
marker: "",
marker: "1",
exact: [
{ name: "toString", text: "(method) toString(): string (+1 overload)", documentation: "Returns a string representation of a string.", },
{ name: "toString", text: "(method) toString(): string (+1 overload)", documentation: "Returns a string representation of a string." },
{ name: "valueOf", text: "(method) valueOf(): string | number", documentation: "Returns the primitive value of the specified object." },
{ name: "toLocaleString", text: "(method) toLocaleString(): string (+1 overload)", documentation: "Returns a date converted to a string using the current locale." },
],
});

verify.completions({
marker: '2',
includes: { name: 'foo' }
})