Skip to content

Commit e9607f1

Browse files
committed
Exclude tuples from suggestion
1 parent 22b9e7a commit e9607f1

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19580,6 +19580,7 @@ namespace ts {
1958019580
}
1958119581

1958219582
function getExactOptionalUnassignableProperties(source: Type, target: Type) {
19583+
if (isTupleType(source) && isTupleType(target)) return emptyArray;
1958319584
return getPropertiesOfType(target)
1958419585
.filter(targetProp => isExactOptionalPropertyMismatch(getTypeOfPropertyOfType(source, targetProp.escapedName), getTypeOfSymbol(targetProp)));
1958519586
}

tests/baselines/reference/strictOptionalProperties1.errors.txt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ tests/cases/compiler/strictOptionalProperties1.ts(20,9): error TS2412: Type 'und
55
tests/cases/compiler/strictOptionalProperties1.ts(28,9): error TS2412: Type 'undefined' is not assignable to type 'string' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.
66
tests/cases/compiler/strictOptionalProperties1.ts(53,5): error TS2412: Type 'undefined' is not assignable to type 'string' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.
77
tests/cases/compiler/strictOptionalProperties1.ts(60,5): error TS2322: Type 'undefined' is not assignable to type 'string'.
8-
tests/cases/compiler/strictOptionalProperties1.ts(64,5): error TS2375: Type '[number, string?, string?]' is not assignable to type '[number, string?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
8+
tests/cases/compiler/strictOptionalProperties1.ts(64,5): error TS2322: Type '[number, string?, string?]' is not assignable to type '[number, string?]'.
99
Target allows only 2 element(s) but source may have more.
10-
tests/cases/compiler/strictOptionalProperties1.ts(73,5): error TS2375: Type '[number, never?, never?, never?]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
10+
tests/cases/compiler/strictOptionalProperties1.ts(73,5): error TS2322: Type '[number, never?, never?, never?]' is not assignable to type '[number, string?, boolean?]'.
1111
Target allows only 3 element(s) but source may have more.
12-
tests/cases/compiler/strictOptionalProperties1.ts(74,5): error TS2375: Type '[never?, never?, true?]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
12+
tests/cases/compiler/strictOptionalProperties1.ts(74,5): error TS2322: Type '[never?, never?, true?]' is not assignable to type '[number, string?, boolean?]'.
1313
Source provides no match for required element at position 0 in target.
14-
tests/cases/compiler/strictOptionalProperties1.ts(75,5): error TS2375: Type '[number, undefined, true]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
14+
tests/cases/compiler/strictOptionalProperties1.ts(75,5): error TS2322: Type '[number, undefined, true]' is not assignable to type '[number, string?, boolean?]'.
1515
Type at position 1 in source is not compatible with type at position 1 in target.
1616
Type 'undefined' is not assignable to type 'string'.
1717
tests/cases/compiler/strictOptionalProperties1.ts(99,7): error TS2375: Type '{ foo: undefined; bar: string; }' is not assignable to type 'InputProps' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
1818
Types of property 'foo' are incompatible.
1919
Type 'undefined' is not assignable to type 'string'.
20-
tests/cases/compiler/strictOptionalProperties1.ts(105,7): error TS2375: Type '[number, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
20+
tests/cases/compiler/strictOptionalProperties1.ts(105,7): error TS2322: Type '[number, undefined]' is not assignable to type '[number, string?, boolean?]'.
2121
Type at position 1 in source is not compatible with type at position 1 in target.
2222
Type 'undefined' is not assignable to type 'string'.
23-
tests/cases/compiler/strictOptionalProperties1.ts(106,7): error TS2375: Type '[number, string, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
23+
tests/cases/compiler/strictOptionalProperties1.ts(106,7): error TS2322: Type '[number, string, undefined]' is not assignable to type '[number, string?, boolean?]'.
2424
Type at position 2 in source is not compatible with type at position 2 in target.
2525
Type 'undefined' is not assignable to type 'boolean'.
26-
tests/cases/compiler/strictOptionalProperties1.ts(107,7): error TS2375: Type '[number, undefined, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
26+
tests/cases/compiler/strictOptionalProperties1.ts(107,7): error TS2322: Type '[number, undefined, undefined]' is not assignable to type '[number, string?, boolean?]'.
2727
Type at position 1 in source is not compatible with type at position 1 in target.
2828
Type 'undefined' is not assignable to type 'string'.
2929
tests/cases/compiler/strictOptionalProperties1.ts(111,7): error TS2375: Type '{ foo: undefined; }' is not assignable to type '{ foo?: number; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
@@ -118,8 +118,8 @@ tests/cases/compiler/strictOptionalProperties1.ts(195,1): error TS2375: Type '{
118118
function f4a(t1: [number, string?], t2: [number, string?, string?]) {
119119
t1 = t2; // Wasn't an error, but should be
120120
~~
121-
!!! error TS2375: Type '[number, string?, string?]' is not assignable to type '[number, string?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
122-
!!! error TS2375: Target allows only 2 element(s) but source may have more.
121+
!!! error TS2322: Type '[number, string?, string?]' is not assignable to type '[number, string?]'.
122+
!!! error TS2322: Target allows only 2 element(s) but source may have more.
123123
}
124124

125125
function f5(t: [number, string?, boolean?]) {
@@ -130,17 +130,17 @@ tests/cases/compiler/strictOptionalProperties1.ts(195,1): error TS2375: Type '{
130130
t = [42, , ,];
131131
t = [42, , , ,]; // Error
132132
~
133-
!!! error TS2375: Type '[number, never?, never?, never?]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
134-
!!! error TS2375: Target allows only 3 element(s) but source may have more.
133+
!!! error TS2322: Type '[number, never?, never?, never?]' is not assignable to type '[number, string?, boolean?]'.
134+
!!! error TS2322: Target allows only 3 element(s) but source may have more.
135135
t = [, , true]; // Error
136136
~
137-
!!! error TS2375: Type '[never?, never?, true?]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
138-
!!! error TS2375: Source provides no match for required element at position 0 in target.
137+
!!! error TS2322: Type '[never?, never?, true?]' is not assignable to type '[number, string?, boolean?]'.
138+
!!! error TS2322: Source provides no match for required element at position 0 in target.
139139
t = [42, undefined, true]; // Error
140140
~
141-
!!! error TS2375: Type '[number, undefined, true]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
142-
!!! error TS2375: Type at position 1 in source is not compatible with type at position 1 in target.
143-
!!! error TS2375: Type 'undefined' is not assignable to type 'string'.
141+
!!! error TS2322: Type '[number, undefined, true]' is not assignable to type '[number, string?, boolean?]'.
142+
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
143+
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
144144
}
145145

146146
function f6() {
@@ -176,19 +176,19 @@ tests/cases/compiler/strictOptionalProperties1.ts(195,1): error TS2375: Type '{
176176
const t1: [number, string?, boolean?] = [1];
177177
const t2: [number, string?, boolean?] = [1, undefined];
178178
~~
179-
!!! error TS2375: Type '[number, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
180-
!!! error TS2375: Type at position 1 in source is not compatible with type at position 1 in target.
181-
!!! error TS2375: Type 'undefined' is not assignable to type 'string'.
179+
!!! error TS2322: Type '[number, undefined]' is not assignable to type '[number, string?, boolean?]'.
180+
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
181+
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
182182
const t3: [number, string?, boolean?] = [1, "string", undefined];
183183
~~
184-
!!! error TS2375: Type '[number, string, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
185-
!!! error TS2375: Type at position 2 in source is not compatible with type at position 2 in target.
186-
!!! error TS2375: Type 'undefined' is not assignable to type 'boolean'.
184+
!!! error TS2322: Type '[number, string, undefined]' is not assignable to type '[number, string?, boolean?]'.
185+
!!! error TS2322: Type at position 2 in source is not compatible with type at position 2 in target.
186+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
187187
const t4: [number, string?, boolean?] = [1, undefined, undefined];
188188
~~
189-
!!! error TS2375: Type '[number, undefined, undefined]' is not assignable to type '[number, string?, boolean?]' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
190-
!!! error TS2375: Type at position 1 in source is not compatible with type at position 1 in target.
191-
!!! error TS2375: Type 'undefined' is not assignable to type 'string'.
189+
!!! error TS2322: Type '[number, undefined, undefined]' is not assignable to type '[number, string?, boolean?]'.
190+
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
191+
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
192192

193193
// Example from #13195
194194

0 commit comments

Comments
 (0)